Skip to content

Instantly share code, notes, and snippets.

@theqabalist
Last active December 24, 2016 23:31
Show Gist options
  • Save theqabalist/c46f2b80f31d46b9baa9a715c558f575 to your computer and use it in GitHub Desktop.
Save theqabalist/c46f2b80f31d46b9baa9a715c558f575 to your computer and use it in GitHub Desktop.
AOC Day 3 Solution
//eslint-disable-next-line no-sync
const input = require('fs').readFileSync(process.argv[2]).toString();
const {pipe, split, map, sort, flip, subtract, filter, splitEvery, transpose, take, concat, lt, __, prop, reduce, head, tail, identity} = require('ramda');
const numericalMatrix = pipe(
split('\n'),
filter(identity),
map(split(/\s/)),
map(filter(identity)),
map(map(parseInt))
);
const validTriangles = pipe(
map(sort(flip(subtract))),
map(x => reduce(subtract, head(x), tail(x))),
filter(lt(__, 0)),
prop('length')
);
const part1 = pipe(
numericalMatrix,
validTriangles
);
const part2 = pipe(
numericalMatrix,
transpose,
map(splitEvery(3)),
reduce(concat, []),
validTriangles
);
console.log(part1(input), part2(input));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment