diff --git a/day02/solution.rb b/day02/solution.rb index 9e2ce05..9392253 100644 --- a/day02/solution.rb +++ b/day02/solution.rb @@ -1,33 +1,36 @@ #!/bin/env ruby -commands = File.readlines('./input').map(&:split).map{ [_1.to_sym,_2.to_i] } +commands = File.readlines('./input').map(&:split).map { [_1.to_sym, _2.to_i] } # Part 1 -dist, depth = 0,0 +dist = 0 +depth = 0 commands.each do |command, unit| - case command - when :forward - dist += unit - when :down - depth += unit - when :up - depth -= unit - end + 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 +dist = 0 +depth = 0 +aim = 0 commands.each do |command, unit| - case command - when :forward - depth += aim * unit - dist += unit - when :down - aim += unit - when :up - aim -= unit - end + case command + when :forward + depth += aim * unit + dist += unit + when :down + aim += unit + when :up + aim -= unit + end end -p dist * depth \ No newline at end of file +p dist * depth