Skip to content

Instantly share code, notes, and snippets.

@gstark
Created January 23, 2014 20:21
Show Gist options
  • Save gstark/8586068 to your computer and use it in GitHub Desktop.
Save gstark/8586068 to your computer and use it in GitHub Desktop.
class Array
def sum
reduce(:+)
end
end
def is_laser(character)
character == '|' ? 1 : 0
end
until ARGF.eof?
north = ARGF.gets.chomp.chars
robot = ARGF.gets.chomp.index("X")
south = ARGF.gets.chomp.chars
blank_line = ARGF.gets
puts ["GO WEST","GO WEST","GO EAST"][north.map.with_index { |c,index| (index + robot + 1)%2 * (index <=> robot) * is_laser(c) }.sum +
south.map.with_index { |c,index| (index + robot )%2 * (index <=> robot) * is_laser(c) }.sum <=> 0]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment