## Ruby 1.9, 109 characters l=[*[r=1]*17,2]*17;c=152;gets.to_i.times{c+=r=(r*r>1?r/18:-r*18)*l[c]*=-1};l[c]=0;puts l.map{|a|"@_ #"[a]}*"" Input via stdin. A function would be 1 character shorter: f=->a{l=[*[r=1]*17,2]*17;c=152;gets.to_i.times{c+=r=(r*r>1?r/18:-r*18)*l[c]*=-1};l[c]=0;puts l.map{|a|"@_ #"[a]}*""} * (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