Skip to content

Instantly share code, notes, and snippets.

@pezholio

pezholio/1.rb

Created Dec 9, 2019
Embed
What would you like to do?
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