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
| const input = require('./input'); | |
| const {Map: createMap, List: list} = require('immutable'); | |
| const {reduce, range, length, filter, identity, split, curry, prop, equals, addIndex, cond, T, pipe, assoc, repeat, head, tail, map, last, init} = require('ramda'); | |
| const rotateArray = arr => [last(arr)].concat(init(arr)); | |
| const mapIndexed = addIndex(map); | |
| const indexArray = mapIndexed((x, i) => [i, x]); | |
| const point = (x, y) => list([x, y]); | |
| const grid = { |
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
| const scaffold = require('./scaffold'); | |
| const {pipe, length, curry, curryN, flip, reduce} = require('ramda'); | |
| const niceParseInt = flip(curryN(2, parseInt))(10); | |
| const states = { | |
| create: (name, local, params, total) => ({name, localBuffer: local, totalBuffer: total, params}), | |
| consumeChar: curry((char, state) => states.create(state.name, state.localBuffer.concat(char), state.params, state.totalBuffer)), | |
| flush: state => state.totalBuffer + state.localBuffer.length | |
| }; |
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
| const scaffold = require('./scaffold'); | |
| const {pipe, toPairs, all, take, multiply, reduce, lensIndex, min, max, clone, prop, partition, groupBy, curry, find, intersection, fromPairs, assoc, filter, identity, flip, sortBy, head, last, curryN, over, lensProp, map} = require('ramda'); | |
| const bots = lensProp('bots'); | |
| const values = lensProp('values'); | |
| const toInt = flip(curryN(2, parseInt))(10); | |
| const parseBot = s => { | |
| const match = s.match(/bot (\d+) gives low to (bot|output) (\d+) and high to (bot|output) (\d+)/); | |
| //eslint-disable-next-line | |
| const [_, bot, lowType, lowAddr, highType, highAddr] = match; |
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, set, curry, over, lensProp, inc, dec, head, tail} = require('ramda'); | |
| const initMachine = curry((c, instructions) => ({ | |
| pc: 0, | |
| registers: { | |
| a: 0, | |
| b: 0, | |
| c, |
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
| //http://adventofcode.com/2016/day/13 | |
| /*eslint no-confusing-arrow: off */ | |
| const input = parseInt(require('./input'), 10); | |
| const {catcat} = require('./helper'); | |
| const {pipe, filter, head, identity, reduce, tail, length, repeat, uniq, chain, map, sortBy, prop, equals, curry} = require('ramda'); | |
| const destination = [31, 39]; | |
| const {Set: set, List: list} = require('immutable'); | |
| const isSpace = ([x, y]) => filter(equals('1'), (x * x + 3 * x + 2 * x * y + y + y * y + input).toString(2)).length % 2 === 0; | |
| const h = ([x, y]) => Math.abs(destination[0] - x) + Math.abs(destination[1] - y); |
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
| //http://adventofcode.com/2016/day/14 | |
| const scaffold = require('./scaffold'); | |
| const {identity, over, memoize, curry, repeat, tap, lensIndex, prop, pipe, reduceRight} = require('ramda'); | |
| const {Range: infRange} = require('immutable'); | |
| const md5 = require('md5'); | |
| const solved = curry((hasher, input) => infRange() | |
| .map(i => [i, hasher(`${input}${i}`), infRange(i + 1, i + 1000).map(i => hasher(`${input}${i}`))]) | |
| .map(over(lensIndex(1), hash => hash.match(/(.)\1\1/))) | |
| .filter(pipe(prop(1), identity)) |
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
| const scaffold = require('./scaffold'); | |
| const {pipe, map, tail, addIndex, all, equals} = require('ramda'); | |
| const {Range: clock} = require('immutable'); | |
| const lineRe = /Disc #(\d+) has (\d+) positions; at time=0, it is at position (\d+)./; | |
| const parseLine = line => { | |
| const [size, position] = tail(tail(map(x => parseInt(x, 10), line.match(lineRe)))); | |
| return {size, position}; | |
| }; |
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) : |
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 {Set: makeSet} = require('immutable'); | |
| const {repeat, pipe, partition, prop, tail, find, uniqBy, inc, zipWith, add, chain, subtract, __, not, addIndex, map, xprod, invoker, head, last, reduce, filter, equals, range} = require('ramda'); | |
| const numFloors = parseInt(process.argv[2], 10); | |
| const numPairs = parseInt(process.argv[3], 10); | |
| const startingState = process.argv[4].split('').map(x => parseInt(x, 10)); | |
| const finalState = repeat(numFloors - 1, numPairs * 2 + 1); | |
| const floorRange = range(0, numFloors); | |
| const floorCount = floors => reduce((count, floor) => count.concat(filter(equals(floor), floors).length), [], floorRange); |
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
| const scaffold = require('./scaffold'); | |
| const md5 = require('md5'); | |
| const {pipe, map, head, filter, prop, toPairs, curry, find, concat, equals, complement, chain, take, reduce, zipWith, add, all} = require('ramda'); | |
| const moves = {U: [0, 1], D: [0, -1], L: [1, 0], R: [-1, 0]}; | |
| const actualPosition = pipe( | |
| map(x => moves[x]), | |
| reduce(zipWith(add), [3, 3]) | |
| ); | |
| const inBounds = dim => dim >= 0 && dim <= 3; |