You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2017/ruby/day_11.rb

27 lines
554 B

dirs = ARGF.read.strip.split(?,)
current = [0, 0, 0]
max = 0
dirs.each do |dir|
delta = case dir
when "nw"
[-1, 1, 0]
when "n"
[0, 1, -1]
when "ne"
[1, 0, -1]
when "sw"
[-1, 0, 1]
when "s"
[0, -1, 1]
when "se"
[1, -1, 0]
else
raise "omg!"
end
current = current.zip(delta).map {|a,b| a + b }
max = [max, current.map(&:abs).sum / 2].max
end
p current
p current.map(&:abs).sum / 2
p max