Skip to content

Instantly share code, notes, and snippets.

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