Created
January 23, 2014 20:21
-
-
Save gstark/8586068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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