Created
December 4, 2015 11:50
-
-
Save NGMarmaduke/cf8bf6bd6504deb7c2ab 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
Location = Struct.new(:x, :y) | |
class Santa | |
attr_accessor :x, :y | |
def initialize | |
@x = @y = 0 | |
end | |
def move(char) | |
case char | |
when '^' | |
@y += 1 | |
when 'v' | |
@y -= 1 | |
when '>' | |
@x += 1 | |
when '<' | |
@x -= 1 | |
end | |
end | |
def location | |
Location.new(@x, @y) | |
end | |
end | |
location_list = [] | |
location_list << Location.new(0, 0) | |
santas = [Santa.new, Santa.new] | |
IO.read('day-3-input.txt').chars.each_with_index do |char, i| | |
santa = santas[i%2] | |
santa.move(char) | |
location_list << santa.location | |
end | |
puts location_list.uniq.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment