Langtons Ant by flagitious

#steps=11000
#steps=100
steps=gets.to_i
board=Hash.new(-1)
x=0
y=0
dx=-1
dy=0
steps.times{
\x09color=board[[x,y]]*-1
\x09board[[x,y]]*=-1
\x09dx,dy=-dy,dx
\x09dx,dy=dx*color,dy*color
\x09x+=dx
\x09y+=dy
}

keys=board.keys.select{|key|board[key]==1}

x1,x2=keys.map{|x,y|x}.minmax
y1,y2=keys.map{|x,y|y}.minmax
out=y1.upto(y2).map{' '*(x2-x1+1)}
keys.map{|x,y|out[y-y1][x-x1]=?#}
puts out#.map(&:rstrip)

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

download

return top