commit 52895f74637076a51b4667fc66dd9de3c5b3d18c Author: Guillaume Dott Date: Tue Dec 10 16:48:57 2019 +0100 feat: add code for day 1 diff --git a/1/input b/1/input new file mode 100644 index 0000000..2a91d86 --- /dev/null +++ b/1/input @@ -0,0 +1,100 @@ +78207 +89869 +145449 +73634 +78681 +81375 +131482 +126998 +50801 +115839 +77949 +53203 +146099 +56912 +59925 +132631 +115087 +89543 +123234 +108110 +109873 +81923 +124264 +87981 +106554 +147239 +73615 +72609 +129684 +84175 +64915 +98124 +74391 +55211 +120961 +119116 +148275 +89605 +115986 +120547 +50299 +137922 +78906 +145216 +80424 +122610 +61408 +97573 +127533 +116820 +76068 +77400 +117943 +85231 +102442 +62002 +58761 +56479 +98200 +85971 +73985 +88908 +82719 +120604 +83378 +88241 +122574 +76731 +99810 +137548 +102617 +105352 +137585 +83238 +118817 +149419 +107629 +63893 +56049 +70693 +83844 +76413 +87021 +90259 +124289 +102527 +139625 +106607 +120241 +101098 +66142 +96591 +82277 +142297 +116671 +131881 +94861 +79741 +73561 +115214 diff --git a/1/script.rb b/1/script.rb new file mode 100755 index 0000000..ef93810 --- /dev/null +++ b/1/script.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +INPUT = __dir__ + '/input' + +def part1 + File.readlines(INPUT).map { |mass| calculate_fuel(mass) }.inject(:+) +end + +def part2 + File.readlines(INPUT).map { |mass| calculate_total_fuel(mass.to_i) }.inject(:+) +end + +def calculate_total_fuel(mass) + fuel = calculate_fuel(mass) + fuel > 0 ? fuel + calculate_total_fuel(fuel) : 0 +end + +def calculate_fuel(mass) + (mass.to_i / 3).floor - 2 +end + +puts "=== Part 1 ===" +puts part1 +puts "=== Part 2 ===" +puts part2