Created
December 2, 2021 09:29
-
-
Save digininja/6b169b686cb1cef00ce60dff34b94d52 to your computer and use it in GitHub Desktop.
advent of code day two part two
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aim=0 | |
depth=0 | |
forward=0 | |
File.readlines('input.txt').each do |line| | |
if /([^ ]*) ([0-9]*)/ =~ line | |
puts "direction: " + $1 + " value " + $2 + "\n" | |
value = $2.to_i | |
movement = $1 | |
if movement == "forward" | |
forward = forward + value | |
depth = depth + (aim * value) | |
else | |
if movement == "down" | |
aim = aim + value | |
else | |
aim = aim - value | |
end | |
end | |
else | |
puts "wrong" | |
end | |
end | |
puts "Forward: " + forward.to_s + "\n" | |
puts "Depth: " + depth.to_s + "\n" | |
puts "Answer: " + (forward * depth).to_s + "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment