Skip to content

Instantly share code, notes, and snippets.

@omardeleo
Created December 10, 2019 00:24
Show Gist options
  • Save omardeleo/b570114a61c6270eb9f51cda2f22556f to your computer and use it in GitHub Desktop.
Save omardeleo/b570114a61c6270eb9f51cda2f22556f to your computer and use it in GitHub Desktop.
AOC-01
// 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