Skip to content

Instantly share code, notes, and snippets.

@NGMarmaduke
Created December 4, 2015 11:50
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 NGMarmaduke/cf8bf6bd6504deb7c2ab to your computer and use it in GitHub Desktop.
Save NGMarmaduke/cf8bf6bd6504deb7c2ab to your computer and use it in GitHub Desktop.
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