-
-
Save pezholio/e6078f30042df506082a2eb53b3e9095 to your computer and use it in GitHub Desktop.
Advent of Code 2019 - Day 1
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
file = File.read('input.txt') | |
answer = file.split("\n").map do |line| | |
(line.to_i / 3).floor - 2 | |
end.inject(0, :+) | |
puts answer |
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
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