Skip to content

Instantly share code, notes, and snippets.

@pezholio
Created December 9, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pezholio/e6078f30042df506082a2eb53b3e9095 to your computer and use it in GitHub Desktop.
Save pezholio/e6078f30042df506082a2eb53b3e9095 to your computer and use it in GitHub Desktop.
Advent of Code 2019 - Day 1
file = File.read('input.txt')
answer = file.split("\n").map do |line|
(line.to_i / 3).floor - 2
end.inject(0, :+)
puts answer
file = File.read('input.txt')
answer = file.split("\n").map do |line|
f = (line.to_i / 3).floor - 2
fuels = [f]
loop do
f = (f / 3).floor - 2
break if f.negative?
fuels << f
end
puts fuels.join(",")
fuels.inject(0, :+)
end.inject(0, :+)
puts answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment