Skip to content

Instantly share code, notes, and snippets.

@Kiwka
Last active December 1, 2019 14:01
Show Gist options
  • Save Kiwka/0f7c6d48d6055bae840112879f8c1adb to your computer and use it in GitHub Desktop.
Save Kiwka/0f7c6d48d6055bae840112879f8c1adb to your computer and use it in GitHub Desktop.
Advent of Code - 2019 - Day 1 - JavaScript
// part 1
const fuel = x => Math.floor(x/3) - 2;
$0.textContent.split("\n").map(Number).map(fuel).filter(i => i > 0).reduce((a, b) => a + b, 0)
// part 2
($0.textContent.split("\n").map(Number).filter(i => i > 0).map(mass => {const res = []; let i = mass; while (i > 0) {i = fuel(i); res.push(i)} return res})).flat().reduce((a, b) => a + b, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment