Langtons Ant by nn

a=[d=0]*4e3
a[p=1525]=1
n="$System.in".toLong()+1
P=[]
n.times{a[p]^=1;p+=[-50,1,50,-1][d=d+3-2*a[p]&3];P<<p%50}
99.times{i->s=(P.min()..P.max()).sum{a[50*i+it]?'#':' '};s=~/#/&&println(s)}

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

download

return to the top page