Skip to main content
added 48 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55

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 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

Ruby 1.9, 108 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.map{|a|"@_
#"[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

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
deleted 115 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55

Ruby 1.9, 109108 characters

f=->z{l=[*[r=1]*17,2]*17;c=152;gets.to_i2]*17;c=152;z.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 6 characters shorter (103):argument.

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|"@_
#"[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
  • (109 -> 108) Code is now a function

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 6 characters shorter (103):

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|"@_
#"[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

Ruby 1.9, 108 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.map{|a|"@_
#"[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
deleted 2 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55

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 character6 characters shorter (103):

f=->a>z{l=[*[r=1]*17,2]*17;c=152;gets.to_i2]*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]}*""}
  • (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

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

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 6 characters shorter (103):

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|"@_
#"[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
added 73 characters in body; added 58 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
added 219 characters in body; added 22 characters in body; edited body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
deleted 26 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
added 41 characters in body; added 53 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
added 26 characters in body; added 53 characters in body; added 68 characters in body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
edited body; deleted 1 characters in body; added 3 characters in body; edited body
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading
Source Link
Ventero
  • 10.1k
  • 3
  • 24
  • 55
Loading