Solved day 2

master
s00ner 2021-12-02 07:39:40 -05:00
parent 3862cfb0b1
commit c629ccd63f
2 changed files with 1033 additions and 0 deletions

1000
day02/input Normal file

File diff suppressed because it is too large Load Diff

33
day02/solution.rb Normal file
View File

@ -0,0 +1,33 @@
#!/bin/env ruby
commands = File.readlines('./input').map(&:split).map{ [_1.to_sym,_2.to_i] }
# Part 1
dist, depth = 0,0
commands.each do |command, unit|
case command
when :forward
dist += unit
when :down
depth += unit
when :up
depth -= unit
end
end
p dist * depth
# Part 2
dist, depth, aim = 0,0,0
commands.each do |command, unit|
case command
when :forward
depth += aim * unit
dist += unit
when :down
aim += unit
when :up
aim -= unit
end
end
p dist * depth