Last active
December 24, 2016 23:31
-
-
Save theqabalist/c46f2b80f31d46b9baa9a715c558f575 to your computer and use it in GitHub Desktop.
AOC Day 3 Solution
This file contains 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
//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