A Pen by Omar De Leo on CodePen.
Created
December 10, 2019 00:24
-
-
Save omardeleo/b570114a61c6270eb9f51cda2f22556f to your computer and use it in GitHub Desktop.
AOC-01
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
| // visit https://adventofcode.com/2019/day/1/input | |
| const masses = document.querySelector('pre').innerText.split(/\r?\n/); | |
| function calculateFuel(mass) { | |
| return Math.floor(mass / 3) - 2 > 0 ? Math.floor(mass / 3) - 2 : 0; | |
| } | |
| function calculateTotalFuel(masses) { | |
| return masses.map(mass => calculateFuel(mass)).reduce((total, fuel) => total + fuel) | |
| } | |
| calculateTotalFuel(masses); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment