Last active
December 24, 2016 23:26
-
-
Save theqabalist/26d8438cf24701a8b2e8aa333adeaa58 to your computer and use it in GitHub Desktop.
AOC Day 16 Solution
This file contains hidden or 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 no-confusing-arrow: off */ | |
| const scaffold = require('./scaffold'); | |
| const {pipe, curry, take, reverse, map, equals, splitEvery} = require('ramda'); | |
| const translation = {0: '1', 1: '0'}; | |
| const expand1 = x => [x, map(x => translation[x], reverse(x)).join('')].join('0'); | |
| const expandTo = curry((size, input) => | |
| input.length >= size ? | |
| take(size, input) : | |
| expandTo(size, expand1(input)) | |
| ); | |
| const checksum = input => | |
| input.length % 2 === 1 ? | |
| input : | |
| checksum(map(x => equals(...x.split('')) ? '1' : '0', splitEvery(2, input)).join('')); | |
| const part1 = pipe( | |
| expandTo(272), | |
| checksum | |
| ); | |
| const part2 = pipe( | |
| expandTo(35651584), | |
| checksum | |
| ); | |
| scaffold.value(part1, part2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment