Langtons Ant by hoozie

w=[0l]
d=[-1,x=y=m=l=0,1,0]
"$System.in".toLong().times{m+=(w[y]^=2**x)>>x&1?-1:1
m&=3
l=x>l?x:l
y+=d[-1-m]
y-w.size()?:w<<0l
if(y<0){w=[0l]+w;y=0}
x+=d[m]
if(x<0){w=w.collect{it*2}
l++
x=0}}
w.any{println((0..l).inject(''){s,i->s+=it>>i&1?'#':' '})}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page