Last active
December 24, 2016 23:30
-
-
Save theqabalist/7226214f4d7bcb6121767f02006149e0 to your computer and use it in GitHub Desktop.
AOC Day 6 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
const input = require('./input'); | |
const {histogram} = require('./helper'); | |
const {pipe, split, transpose, map, join, head, invoker, sort, prop, sortBy} = require('ramda'); | |
const histogramFrequency = pipe( | |
split('\n'), | |
transpose, | |
map(join('')), | |
map(sort((x, y) => x.localeCompare(y))), | |
map(histogram), | |
map(sortBy(prop(1))) | |
); | |
const firstOfFirstCompacted = pipe( | |
map(head), | |
map(head), | |
join('') | |
); | |
const part1 = pipe( | |
histogramFrequency, | |
map(invoker(0, 'reverse')), | |
firstOfFirstCompacted | |
); | |
const part2 = pipe( | |
histogramFrequency, | |
firstOfFirstCompacted | |
); | |
console.log(part1(input), part2(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment