Langtons Ant by recursive

n=input()
r=C=n%984%131%91
c=C/2+~C%2
B=[" "*C]*99
h=1
v=0
while n:l=B[r];d=cmp(l[c],"!");h,v=d*v,-d*h;B[r]=l[:c]+"  #"[d]+l[c+1:];r-=v;c-=h;n-=1
for b in B:
 if"#"in b:print b

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

download

return to the top page