ran rubocop

master
s00ner 2021-12-02 08:06:03 -05:00
parent c629ccd63f
commit 19a0563550
1 changed files with 24 additions and 21 deletions

View File

@ -1,33 +1,36 @@
#!/bin/env ruby #!/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 # Part 1
dist, depth = 0,0 dist = 0
depth = 0
commands.each do |command, unit| commands.each do |command, unit|
case command case command
when :forward when :forward
dist += unit dist += unit
when :down when :down
depth += unit depth += unit
when :up when :up
depth -= unit depth -= unit
end end
end end
p dist * depth p dist * depth
# Part 2 # Part 2
dist, depth, aim = 0,0,0 dist = 0
depth = 0
aim = 0
commands.each do |command, unit| commands.each do |command, unit|
case command case command
when :forward when :forward
depth += aim * unit depth += aim * unit
dist += unit dist += unit
when :down when :down
aim += unit aim += unit
when :up when :up
aim -= unit aim -= unit
end end
end end
p dist * depth p dist * depth