Skip to content

Instantly share code, notes, and snippets.

@joawan
Created December 1, 2021 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joawan/e47306c5c941f05c502c5e471aa87ee1 to your computer and use it in GitHub Desktop.
Save joawan/e47306c5c941f05c502c5e471aa87ee1 to your computer and use it in GitHub Desktop.
adventofcode2021
const fs = require('fs');
const file = fs.readFileSync(`./${process.argv[2]}`);
const numbers = file.toString().split("\n").map(e => +e);
const increases = numbers.map((n, i, a) => n > a[i-1]);
const count = increases.filter(e => e).length;
console.log(count);
const fs = require('fs');
const file = fs.readFileSync(`./${process.argv[2]}`);
const numbers = file.toString().split("\n").map(e => +e);
const sums = numbers.map((n, i, a) => n + a[i+1] + a[i+2]).filter(Number);
const increases = sums.map((n, i, a) => n > a[i-1]);
const count = increases.filter(e => e).length;
console.log(count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment