Created
December 2, 2021 09:28
-
-
Save digininja/10094e9ed2124c313eb2b6c08b5b866d to your computer and use it in GitHub Desktop.
advent of code day two part one
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
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 | |
else | |
if movement == "down" | |
depth = depth + value | |
else | |
depth = depth - 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