Ruby 1.9, 108104 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;puts l;l[c]=0;l.map{|a|"@_|a|putc"@_
#"[a]}*""}
Input via function argument.
- (146 -> 142) Inlined
m
- (142 -> 140) Check for
r*r>1
instead ofr.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