Langton's ant ASCII art.

GolfScript - 67 chars

~17.'_'*n+*\153:|;{|/()[124^.2/6+:6.1&17*)\2&(*|+:|;]@++}*|/();'@'@

hallvabo's Python solution is the most similar to this, so I'll only describe the main differences.

The board is stored as a string instead of an array. This is so we can update a value on the board with less characters (as strings are always flat), and so getting it to the desired output format is easy.

The ant position is incremented by the formula ((d&1)*17+1)*((d&2)-1) (i.e. .1&17*)\2&(*), where d is the direction. We use the variable 6 so we can skip initialization.


Ruby 1.9, 104 characters

f=->z{l=[*[r=1]*17,2]*17;c=152;z.times{c+=r=(r*r>1?r/18:-r*18)*l[c]*=-1};l[c]=0;l.map{|a|putc"@_
#"[a]}}

Input via function argument.

  • (146 -> 142) Inlined m
  • (142 -> 140) Check for r*r>1 instead of r.abs>1
  • (142 -> 128) Use String#scan to generate the output. Changed a == to >
  • (128 -> 125) Removed obsolete variable
  • (125 -> 122) Replace String#tr with a conditional
  • (122 -> 122) Now generates the same output as the updated examples
  • (122 -> 111) Use ints instead of chars when generating the ant's path.
  • (111 -> 109) Reorder some expressions to save parentheses
  • (109 -> 108) Code is now a function
  • (108 -> 104) Print every character individually

Python, 123

n=input()
d=x=152
g=(17*[95]+[10])*17
while n:d+=g[x]/2;g[x]^=124;x+=(1,-18,-1,18)[d%4];n-=1
g[x]=64
print"%c"*306%tuple(g)

Just a slight reworking of my Python solution from http://golf.shinh.org/p.rb?Langtons+Ant.