Skip to content

Instantly share code, notes, and snippets.

@theqabalist
Last active December 24, 2016 23:30
Show Gist options
  • Save theqabalist/7226214f4d7bcb6121767f02006149e0 to your computer and use it in GitHub Desktop.
Save theqabalist/7226214f4d7bcb6121767f02006149e0 to your computer and use it in GitHub Desktop.
AOC Day 6 Solution
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