Skip to content

Instantly share code, notes, and snippets.

@digininja
Created December 2, 2021 09:29
Show Gist options
  • Save digininja/6b169b686cb1cef00ce60dff34b94d52 to your computer and use it in GitHub Desktop.
Save digininja/6b169b686cb1cef00ce60dff34b94d52 to your computer and use it in GitHub Desktop.
advent of code day two part two
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