1
Fork 0
advent-of-code-2021/puzzles/02_2/main.rb
2021-12-09 11:22:17 +01:00

21 lines
425 B
Ruby

def run(f)
horizontal = 0
depth = 0
aim = 0
f.each do |line|
command, distance = line.split(' ')
distance = Integer(distance)
case command
when 'forward'
horizontal += distance
depth += (aim * distance)
when 'down'
aim += distance
when 'up'
aim -= distance
end
end
return horizontal * depth
end