Skip to content

Instantly share code, notes, and snippets.

@gstark
Created January 23, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gstark/8586425 to your computer and use it in GitHub Desktop.
Save gstark/8586425 to your computer and use it in GitHub Desktop.
class String
def py_slice(start, step = 1)
start.step(step < 0 ? 0 : self.length, step).map { |index| self[index] }
end
end
input = ARGF.readlines
for i in Range.new(0,input.size).step(4)
northLasers, conveyorBelt, southLasers = input[i,3]
x = conveyorBelt.index('X')
west = (northLasers.py_slice(x,-2) + southLasers.py_slice(x-1,-2)).count('|')
east = (northLasers.py_slice(x, 2) + southLasers.py_slice(x+1, 2)).count('|')
puts east < west ? "GO EAST" : "GO WEST"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment