Code Golf: Playing Cubes
Perl 157 characters
This entry was inspired by gnibbler's Ruby entry, including the part about embedding the cube in the code. Also thanks to Kinopiko for schooling me on the 4 arg version of substr
.
@O=($/.$"x99)x99;map{for$n(0..$_-1,$_..-1){map{substr$O[50-2*$n+$_],$W+4/$_,6,
(_,"__"
,"/__ /|",
"| | |",
"|___|/")[$_]}1..4}$W+=4}@ARGV;print grep/\S/,@O
Explanation:
Line 1: Choose where cubes go
Lines 2-5: Put cubes where cubes go, print
Ruby - 233
mutable strings ;) No arbitrary "99" limits. pfft :p
Had to lose the picture of the cube in the source though
S=gets.split.map{|x|x.to_i}<<0
S.max.downto(S.min){|y|e=" ";q=e*3;r=e*3
S.map{|x|a=0,x;if(w=a.min)<=y&&x!=0&&y<z=a.max
r[-3,4]="| | |";q[-3,4]="|___|/"+(y>w ?"|":e)else(z=z!=y)?q+=e*4:q[-2,4]="/__ /|"
r+=z ?e*4:"__ "end}
puts r,q}
Ruby - 243
Delete the extra space I put in there to get the nice picture of the cube
S=gets.split.map{|x|x.to_i}<<0
S.max.downto(S.min){|y|e=" ";q=e*3;r=e*3
S.map{|x|a=0,x;if(w=a.min)<=y&&x!=0&&y<=z=a.max
if z==y;r+="__ "
q[-2,3]="/__ /|"else
r[-3,4]="| | |"
q[-3,4]="|___|/"+(y>w ?e:"|")end
else r+=e*4;q+=e*4 end}
puts r,q}
$ echo 1 3 7 3 3 |ruby pc.rb __ /__ /| | | | |___|/| | | | |___|/| | | | |___|/| _| | |__ __ /__|___|/__ /__ /| | | | | | | |___|___|___|___|/| _| | | | | | /__|___|___|___|___|/| | | | | | | | |___|___|___|___|___|/
Python - 249
The second for loop is indented with tab
S=map(int,raw_input().split())+[0]
for y in range(max(S),min(S)-1,-1):
q=r=e=" "*4
for x in S:
w=x*(x<0);z=x*(x>0)
if w<=y<z:r=r[:-3]+"| | |";q=q[:-3]+"|___|/"+" |"[y>w]
elif(y==z)*x:q=q[:-2]+"/__ /|";r+="__ "
else:q+=e;r+=e
print r+"\n"+q
Python - 393
S=map(int,raw_input().split())+[0]
for Y in range(max(S),min(S)-1,-1):
Q=R="";B=s=t=" "*4;N=0
for y in S:
if(y>0)*(y==Y)+(Y==0)*(y<0):
q="_ _";r=" /__";s="_ ";t=" /| "
if(N<y>0)+(N==0):q=" _"
if y<N>0:q="| |_";r="|/__"
elif(y>Y>=0)+(y<=Y<0):q="| ";r="|___";s="| | ";t="|/"+("| "[(y==Y<0)+(Y==0)])+" "
else:q=s;r=t;s=t=B
Q+=q;R+=r;N=y
print Q.rstrip()+"\n"+R.rstrip()
Ruby, 261 258 250 242
c=[]
n=99
$F.map{|e|e=e.to_i
c<<(e<0?[e,-1]:[0,e-1])}
m=[]
x=0
c.map{|d|x+=4
k,l=d
(k+n..l+n).map{|y|y*=2
[[3,3,2,'__'],[2,1,6,'/__ /|'],[1,0,7,'| | |'],[0,0,6,'|___|/']].map{|e|a,b,c,s=e
(m[y+a]||=' '*79)[x+b,c]=s}}}
puts m.compact.reverse
Run with ruby -n -a v2.rb
This entry is slightly overdesigned in that it can begin and end stacks at any level, not just at 0. There is no way to specify this in the "competition version", but if you replace the first 4 lines with c=eval $_;n=99
then it drops to 203 bytes and you can do: <
[[-3,3],[-3,-2],[2,3],[-3,-3],[-2,-1],[3,3],[2,2],[1,1],[0,0]]
__ __ __ /__ /| /__ /| /__ /| | | | | | | | | |__ |___|/| |___|/| |___|/__ /| | | | | | | | | |__ |___|/| |___|/ |___|/__ /| | | | | | |__ |___|/| |___|/__ /| | | | __ | | | |___|/| /__ /| |___|/ | | |__ | | | |___|/__ /| |___|/| | | | | _| | | |___|___|/| /__|___|/ | | | | | | | |___|___|/ |___|/