Skip to content

Instantly share code, notes, and snippets.

@WOOLAN
WOOLAN / 2.js
Created December 2, 2016 08:58
const part = parseInt(process.argv[2], 10) || 1;
const input = (process.argv[3] || 'ULL\nRRDDD\nLURDL\nUUUUD').split('\n');
/* Part 1 */
let keypad = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
let button = { x: 1, y: 1 };
let calc = (coord, modifier) => button[coord] + modifier < 0 ? 0 : (button[coord] + modifier > 2 ? 2 : button[coord] + modifier);
/* Part 2 */
if (part === 2) {
@WOOLAN
WOOLAN / 1.js
Created December 1, 2016 21:10
const part = process.argv[2] || 1;
const input = (process.argv[3] || 'R5, L2, L1, R1, R3, R3, L3, R3, R4, L2, R4, L4, R4, R3, L2, L1, L1, R2, R4, R4, L4, R3, L2, R1, L4, R1, R3, L5, L4, L5, R3, L3, L1, L1, R4, R2, R2, L1, L4, R191, R5, L2, R46, R3, L1, R74, L2, R2, R187, R3, R4, R1, L4, L4, L2, R4, L5, R4, R3, L2, L1, R3, R3, R3, R1, R1, L4, R4, R1, R5, R2, R1, R3, L4, L2, L2, R1, L3, R1, R3, L5, L3, R5, R3, R4, L1, R3, R2, R1, R2, L4, L1, L1, R3, L3, R4, L2, L4, L5, L5, L4, R2, R5, L4, R4, L2, R3, L4, L3, L5, R5, L4, L2, R3, R5, R5, L1, L4, R3, L1, R2, L5, L1, R4, L1, R5, R1, L4, L4, L4, R4, R3, L5, R1, L3, R4, R3, L2, L1, R1, R2, R2, R2, L1, L1, L2, L5, L3, L1').split(', ');
let direction = 0;
let positions = [{ x: 0, y: 0 }];
function walk(s) {
let pos = Object.assign({}, positions[positions.length - 1]);
for (let i = 0; i < s; ++i) {