Python 3.5, 328 326 313 305 295 248 bytes
(Thanks to Kevin Lau for the tip about reducing the size of the ternary statements!)
def s(w,h,d):R,M=range,max;S,V,L=' |/';O=w-2;D=d-M(0,d-h);Q=h-M(0,h-d);print('\n'.join([S*(d-i)+L+' -'[i<1]*O+L+S*[h-1,i][i<=D-1]+'/|'[i<=D-1]for i in R(D+M(0,d-h))]+[V+[' -'[i==h],'_'][i<2]*O+V+S*[i-1,d][i>Q]+'/|'[i>Q]for i in R(Q+M(0,h-d),0,-1)]))
Takes input as 3 integers in the order of width, height, depth
. Will golf more over time wherever I can.
Try it online! (Ideone)
Explanation:
For the purposes of this explanation, assume the function was executed with the arguments (3,2,3)
where 3 is the width (w
), 2 is the height (h
), and 3 is the depth (d
). That being said, let me begin by showing the main part of the entire function:
'\n'.join([S*(d-i)+L+' -'[i<1]*O+L+S*[h-1,i][i<=D-1]+'/|'[i<=D-1]for i in R(D+M(0,d-h))]+[V+[' -'[i==h],'_'][i<2]*O+V+S*[i-1,d][i>Q]+'/|'[i>Q]for i in R(Q+M(0,h-d),0,-1)])
Here, the two lists that make up the entire "house" are created and then joined together by literal new lines (\n
). Let's call them list a
and list b
respectively, and analyze each one of them:
Here is where list a
is created:
[S*(d-i)+L+' -'[i<1]*O+L+S*[h-1,i][i<=D-1]+'/|'[i<=D-1]for i in R(D+M(0,d-h))]
This list contains the first d
lines of the house. Here, i
is each number in the range 0=>(d-(d-h))+d-h
where d-h=0
if negative or zero. To start, d-i
spaces are added to the list, followed by a /
and then whatever is returned by a compressed conditional statement. In this conditional statement, w-2
number of spaces are returned if i>1
. Otherwise the same number of -
are returned. Then, these are followed up by another /
, and then spaces, where the number of spaces now depends on whether or not i<=d-(d-h)-1
. If it is, then i
spaces are added. Otherwise, h-1
spaces are added. Finally, this is all topped off by either a /
or a |
, where |
is added if i<=d-(d-h)-1
, otherwise a /
is added. In this case of a 3x2x3
prism, this would be returned by list a
:
/-/|
/ / |
/ / /
Here is where list b
is created:
[V+[' -'[i==h],'_'][i<2]*O+V+S*[i-1,d][i>Q]+'/|'[i>Q]for i in R(Q+M(0,h-d),0,-1)]`
This lists contains the rest of the lines of the prism. In this list, i
is each integer in the range (h-(h-d))+h-d=>0
where h-d=0
if negative or zero. To start this list off, firstly a |
is added since these lines always start with a |
. Then, either a space, -
, or _
is added depending on whether or not i=h
or i<2
. If i<2
, then a _
is added. Otherwise, a -
is added if i=h
, or a space is added if i>h
or i<h
or i>2
. After this decision has been made, then w-2
number of the chosen character is added. After this, another |
is added, and then either i-1
or d
number of spaces are added. If i>h-(h-d)
, then a d
number of spaces are added. Otherwise, i-1
number of spaces are added. Finally, this is all topped off with either a |
or a /
, in which a |
is added if i>h-(h-d)
, or a /
is added if i<=h-(h-d)
. In the case of a 3x2x3
prism, list b
returns:
|-| /
|_|/
After the 2 lists have been created, they are finally joined with literal new lines (\n
) using '\n'.join()
. This is your completed prism, and in this case, would come to look like this:
/-/|
/ / |
/ / /
|-| /
|_|/
3 2 10
? \$\endgroup\$