Skip to content

Instantly share code, notes, and snippets.

View theqabalist's full-sized avatar

Brandon Keown theqabalist

View GitHub Profile
### Keybase proof
I hereby claim:
* I am theqabalist on github.
* I am lambdajoshu (https://keybase.io/lambdajoshu) on keybase.
* I have a public key ASCr5JIspD70Y_esZTPoG1f_JE8Ccfv6ukGjlWC8hGiLCgo
To claim this, I am signing this object:
@theqabalist
theqabalist / solution25.js
Created December 28, 2016 07:02
AOC Day 25 Solution
/*eslint no-confusing-arrow: off*/
const scaffold = require('./scaffold');
const {pipe, set, curry, over, lensProp, inc, repeat, dec, head, tail} = require('ramda');
const {inspect} = require('util');
const {usleep} = require('sleep');
const initMachine = curry((a, instructions) => ({
pc: 8,
registers: {
a,
@theqabalist
theqabalist / solution24.js
Created December 28, 2016 05:57
AOC Day 24 Solution
/*eslint no-confusing-arrow: off, no-unused-vars: off*/
const {Set, Map, Record} = require('immutable');
const {pipe, range, xprod, head, isEmpty, over, lensProp, aperture, memoize, concat, splitEvery, sortBy, zipWith, add, equals, chain, __, prop, tail, curry, flip, curryN, filter, map, invoker, addIndex, reduce} = require('ramda');
const reduceIndexed = addIndex(reduce);
const toInt = flip(curryN(2, parseInt))(10);
const pairs = pipe(
range(0),
r => xprod(r, r),
filter(([x, y]) => x !== y),
@theqabalist
theqabalist / solution23.js
Created December 27, 2016 18:58
AOC Day 23 Solution
/*eslint no-confusing-arrow: off*/
const scaffold = require('./scaffold');
const {pipe, set, curry, join, reduce, and, prop, map, split, lensIndex, __, over, lensProp, inc, dec, head, tail} = require('ramda');
const {sleep} = require('sleep');
const initMachine = curry((a, instructions) => ({
pc: 0,
registers: {
a,
b: 0,
@theqabalist
theqabalist / solution22.js
Created December 27, 2016 00:48
AOC Day 22 Solution
const scaffold = require('./scaffold');
const {pipe, tail, range, reduce, find, map, curry, assoc, filter, prop, tap, lte, chain, length} = require('ramda');
const {inspect} = require('util');
const parseLine = line => map(x => parseInt(x, 10), tail(line.match(/\/dev\/grid\/node-x(\d+)-y(\d+)\s+(\d+)T\s+(\d+)T\s+(\d+)T\s+(\d+)%/)));
const astify = ([x, y, size, used, avail, perc]) => ({x, y, size, used, avail, perc});
const adjacency = curry((nodes, node) => assoc('adj', node.used === 0 ? [] : filter(n2 => n2.avail >= node.used, nodes), node));
const classifyNode = ([width, column], [height, row], node) =>
row === 0 && column === width - 1 ? 'G' :
@theqabalist
theqabalist / solution21.js
Created December 26, 2016 22:36
AOC Day 21 Solution
const scaffold = require('./scaffold');
const {curry, indexOf, map, min, prop, last, join, equals, max, head, isEmpty, flatten, range, tail, pipe, filter, identity, reduce} = require('ramda');
const assert = require('assert');
const sliceAround = (i, arr) => arr.slice(0, i).concat(arr.slice(i + 1));
//eslint-disable-next-line
const perms = arr => arr.length === 1 ? arr : map(flatten, reduce((ps, i) => {
const branch = arr[i];
const smaller = sliceAround(i, arr);
const subs = map(x => [branch, x], perms(smaller));
@theqabalist
theqabalist / solution20.js
Created December 26, 2016 06:20
AOC Day 20 Solution
const scaffold = require('./scaffold');
const {map, last, curry, head, all, inc, isEmpty, pipe, sortBy, prop, reduce, partition} = require('ramda');
const parseLine = line => {
const [match, min, max] = line.match(/(\d+)-(\d+)/).map(x => parseInt(x, 10));
return {min, max};
};
const deepenConsolidation = curry((consolidated, ranges) => {
if (all(min => min > consolidated.max + 1, map(prop('min'), ranges))) {
@theqabalist
theqabalist / solution19.js
Created December 26, 2016 04:53
AOC Day 19 Solution
const scaffold = require('./scaffold');
const {subtract} = require('ramda');
const {Range: infRange, Repeat: repeater} = require('immutable');
/* canonical, semantic solution */
// const filterIndexed = addIndex(filter);
// const removeVictim = curry(([id], l) => filter(([xid]) => xid !== id, l));
// const steal = ([x, xn], [y, yn]) => [x, xn + yn];
//
// const rotationReduction = curry((targeter, list) => {
@theqabalist
theqabalist / helper.js
Created December 25, 2016 06:48
AOC Day 18 Solution
/*eslint no-confusing-arrow: off*/
module.exports = (function ({curry, call, complement, identity, tap, invoker, pipe, init, map, filter, reduce, is, not, compose, lte, equals, head, last, fromPairs}) {
const iterate = curry((f, base) => () => [base, iterate(f, f(base))]);
const coreq = {
head: pipe(call, head),
tail: pipe(call, last),
map: curry((f, iter) => () => [f(coreq.head(iter)), coreq.map(f, coreq.tail(iter))]),
filter: curry((pred, iter) => {
const h = coreq.head(iter);
return pred(h) ?
@theqabalist
theqabalist / solution17.js
Created December 24, 2016 23:26
AOC Day 17 Solution
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;