diff --git a/src/2015/day11.js b/src/2015/day11.js index fd88d27c..f577095c 100644 --- a/src/2015/day11.js +++ b/src/2015/day11.js @@ -1,5 +1,5 @@ -let abc = "abcdefghijklmnopqrstuvwxyz"; -let subStrings = abc +const abc = "abcdefghijklmnopqrstuvwxyz"; +const subStrings = abc .split("") .map((x, i) => abc.substr(i, 3)) .filter(x => x.length === 3); diff --git a/src/2015/day13.js b/src/2015/day13.js index df1e3a49..96df4366 100644 --- a/src/2015/day13.js +++ b/src/2015/day13.js @@ -8,7 +8,7 @@ function longest(graph, curr, visited) { } function parse(input) { - let signs = { gain: +1, lose: -1 }; + const signs = { gain: +1, lose: -1 }; let graph = input .split("\n") .map(x => diff --git a/src/2015/day16.js b/src/2015/day16.js index 4eb4644f..316d4828 100644 --- a/src/2015/day16.js +++ b/src/2015/day16.js @@ -1,4 +1,4 @@ -let expect1 = { +const expect1 = { id: () => true, children: 3, cats: 7, @@ -12,7 +12,7 @@ let expect1 = { perfumes: 1, }; -let expect2 = { +const expect2 = { ...expect1, cats: x => x > expect1.cats, trees: x => x > expect1.trees, diff --git a/src/2015/day21.js b/src/2015/day21.js index 2f5fa946..1e8de1c5 100644 --- a/src/2015/day21.js +++ b/src/2015/day21.js @@ -1,5 +1,5 @@ function calcOptions() { - let items = { + const items = { weapons: [ { name: "dagger", cost: 8, damage: 4, armor: 0 }, { name: "shortsword", cost: 10, damage: 5, armor: 0 }, diff --git a/src/2015/day22.js b/src/2015/day22.js index bad77da6..5c29090c 100644 --- a/src/2015/day22.js +++ b/src/2015/day22.js @@ -1,4 +1,4 @@ -let spells = { +const spells = { Missile: { mana: 53, effect: game => { diff --git a/src/2015/day23.js b/src/2015/day23.js index 6cd10632..079ee093 100644 --- a/src/2015/day23.js +++ b/src/2015/day23.js @@ -1,4 +1,4 @@ -let operations = { +const operations = { hlf: (state, p1) => ({ ...state, [p1]: state[p1] / 2, next: state.next + 1 }), tpl: (state, p1) => ({ ...state, [p1]: state[p1] * 3, next: state.next + 1 }), inc: (state, p1) => ({ ...state, [p1]: state[p1] + 1, next: state.next + 1 }), diff --git a/src/2016/day01.js b/src/2016/day01.js index c04e27f7..055c6276 100644 --- a/src/2016/day01.js +++ b/src/2016/day01.js @@ -1,4 +1,4 @@ -let directions = [ +const directions = [ { y: 1, x: 0 }, { y: 0, x: 1 }, { y: -1, x: 0 }, diff --git a/src/2016/day02.js b/src/2016/day02.js index c563fc91..cf14033b 100644 --- a/src/2016/day02.js +++ b/src/2016/day02.js @@ -1,4 +1,4 @@ -let directions = { +const directions = { D: { y: 1, x: 0 }, R: { y: 0, x: 1 }, U: { y: -1, x: 0 }, @@ -28,7 +28,7 @@ function solve(input, keypad, start) { .join(""); } -let keypad1 = [ +const keypad1 = [ ["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], @@ -38,7 +38,7 @@ export function part1(input) { return solve(input, keypad1, { x: 1, y: 1 }); } -let keypad2 = [ +const keypad2 = [ [NaN, NaN, "1", NaN, NaN], [NaN, "2", "3", "4", NaN], ["5", "6", "7", "8", "9"], diff --git a/src/2016/day12.js b/src/2016/day12.js index 3dca6454..31393d57 100644 --- a/src/2016/day12.js +++ b/src/2016/day12.js @@ -1,4 +1,4 @@ -let ops = { +const ops = { cpy: (src, register) => state => (state[register] = src.match(/^\d+$/) ? +src : state[src]), inc: register => state => state[register]++, diff --git a/src/2016/day20.js b/src/2016/day20.js index 20b4e7a6..c0fb1cf2 100644 --- a/src/2016/day20.js +++ b/src/2016/day20.js @@ -1,4 +1,4 @@ -let MAX_IP = 4294967295; +const MAX_IP = 4294967295; function merge(ranges) { ranges.sort((a, b) => a[0] - b[0]); diff --git a/src/2016/day21.js b/src/2016/day21.js index 30a4768c..855553ff 100644 --- a/src/2016/day21.js +++ b/src/2016/day21.js @@ -1,6 +1,6 @@ -let regexp = +const regexp = /^(swap position|swap letter|rotate based|rotate|reverse positions|move position) ([^\s]+)\s.*\s([^\s]+)$/; -let ops = { +const ops = { "swap position": (a, b) => str => { [a, b] = [+a, +b].sort((a, b) => a - b); let arr = str diff --git a/src/2016/day23.js b/src/2016/day23.js index 59995782..e8779cd5 100644 --- a/src/2016/day23.js +++ b/src/2016/day23.js @@ -1,4 +1,4 @@ -let ops = { +const ops = { cpy: (src, register) => state => { if (state[register] !== undefined) { src = state[src] === undefined ? +src : state[src]; diff --git a/src/2016/day25.js b/src/2016/day25.js index 5563b0a8..50cf6b4d 100644 --- a/src/2016/day25.js +++ b/src/2016/day25.js @@ -1,4 +1,4 @@ -let ops = { +const ops = { cpy: (src, register) => state => (state[register] = state[src] === undefined ? +src : state[src]), inc: register => state => state[register]++, diff --git a/src/2017/day18.js b/src/2017/day18.js index d74bc796..a716643a 100644 --- a/src/2017/day18.js +++ b/src/2017/day18.js @@ -10,7 +10,7 @@ export function getter(state, p) { } export function parse(input, ops2 = {}, debug = undefined) { - let ops = { + const ops = { snd: p1 => state => (state.sound = getter(state, p1)), set: (p1, p2) => state => (state[p1] = getter(state, p2)), add: (p1, p2) => state => diff --git a/src/2017/day19.js b/src/2017/day19.js index 4db57c38..c5f5c556 100644 --- a/src/2017/day19.js +++ b/src/2017/day19.js @@ -6,7 +6,7 @@ function findEntryPoint(route) { return { x: route[0].indexOf("|"), y: 0 }; } -let next = { +const next = { down: ({ x, y }) => ({ x, y: y + 1 }), up: ({ x, y }) => ({ x, y: y - 1 }), left: ({ x, y }) => ({ x: x - 1, y }), diff --git a/src/2017/day21.js b/src/2017/day21.js index 8c2f4db1..88e2b4c3 100644 --- a/src/2017/day21.js +++ b/src/2017/day21.js @@ -1,5 +1,5 @@ -let pattern = [".#.", "..#", "###"]; -let permutations2 = [ +const pattern = [".#.", "..#", "###"]; +const permutations2 = [ [1, 2, 3, 4], [3, 4, 1, 2], [1, 3, 2, 4], @@ -9,7 +9,7 @@ let permutations2 = [ [4, 2, 3, 1], [2, 4, 1, 3], ]; -let permutations3 = [ +const permutations3 = [ [1, 2, 3, 4, 5, 6, 7, 8, 9], [7, 8, 9, 4, 5, 6, 1, 2, 3], [1, 4, 7, 2, 5, 8, 3, 6, 9], diff --git a/src/2017/day22.js b/src/2017/day22.js index 24f5dad6..ba8ba7f7 100644 --- a/src/2017/day22.js +++ b/src/2017/day22.js @@ -1,18 +1,18 @@ -let turnLeft = { +const turnLeft = { U: "L", D: "R", L: "D", R: "U", }; -let turnRight = { +const turnRight = { U: "R", D: "L", L: "U", R: "D", }; -let turnBackward = { +const turnBackward = { U: "D", D: "U", L: "R", diff --git a/src/2018/day05.js b/src/2018/day05.js index 271a25e9..2bb66aaa 100644 --- a/src/2018/day05.js +++ b/src/2018/day05.js @@ -1,6 +1,6 @@ -let u = x => x.toUpperCase(); -let abc = "abcdefghijklmnopqrstuvwxyz".split(""); -let kill = abc.reduce((arr, x) => arr.concat([x + u(x), u(x) + x]), []); +const u = x => x.toUpperCase(); +const abc = "abcdefghijklmnopqrstuvwxyz".split(""); +const kill = abc.reduce((arr, x) => arr.concat([x + u(x), u(x) + x]), []); export function part1(input) { let len; diff --git a/src/2018/day07.js b/src/2018/day07.js index b4677daa..188be71a 100644 --- a/src/2018/day07.js +++ b/src/2018/day07.js @@ -1,4 +1,4 @@ -let abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"; function next(prerequisites, done) { let options = []; diff --git a/src/2018/day13.js b/src/2018/day13.js index 32a155ff..69571a11 100644 --- a/src/2018/day13.js +++ b/src/2018/day13.js @@ -1,13 +1,13 @@ -let position = cart => `${cart.x},${cart.y}`; -let onSlash = { ">": "^", "<": "v", "^": ">", "v": "<" }; -let onBackSlash = { ">": "v", "<": "^", "^": "<", "v": ">" }; -let nextTurn = { left: "straight", straight: "right", right: "left" }; -let onTurn = { +const position = cart => `${cart.x},${cart.y}`; +const onSlash = { ">": "^", "<": "v", "^": ">", "v": "<" }; +const onBackSlash = { ">": "v", "<": "^", "^": "<", "v": ">" }; +const nextTurn = { left: "straight", straight: "right", right: "left" }; +const onTurn = { left: { ">": "^", "<": "v", "^": "<", "v": ">" }, right: { ">": "v", "<": "^", "^": ">", "v": "<" }, straight: { ">": ">", "<": "<", "^": "^", "v": "v" }, }; -let onMove = { +const onMove = { ">": c => c.x++, "<": c => c.x--, "^": c => c.y--, diff --git a/src/2018/day15.js b/src/2018/day15.js index 2487c521..e633229c 100644 --- a/src/2018/day15.js +++ b/src/2018/day15.js @@ -1,8 +1,8 @@ -let pos = ({ x, y }) => `${x},${y}`; -let count = (units, type) => units.filter(u => u.type === type).length; +const pos = ({ x, y }) => `${x},${y}`; +const count = (units, type) => units.filter(u => u.type === type).length; function attackIfPossible(map, units, unit) { - let inRange = u => Math.abs(u.x - unit.x) + Math.abs(u.y - unit.y) === 1; + const inRange = u => Math.abs(u.x - unit.x) + Math.abs(u.y - unit.y) === 1; let attack = units .filter(u => u.type !== unit.type && inRange(u)) .sort((a, b) => a.hit - b.hit || a.y - b.y || a.x - b.x) diff --git a/src/2018/day16.js b/src/2018/day16.js index dfdda684..b514bb70 100644 --- a/src/2018/day16.js +++ b/src/2018/day16.js @@ -1,4 +1,4 @@ -let ops = { +const ops = { addr: (r, i1, i2, o) => (r[o] = r[i1] + r[i2]), addi: (r, i1, i2, o) => (r[o] = r[i1] + i2), mulr: (r, i1, i2, o) => (r[o] = r[i1] * r[i2]), @@ -16,7 +16,7 @@ let ops = { eqri: (r, i1, i2, o) => (r[o] = r[i1] === i2 ? 1 : 0), eqrr: (r, i1, i2, o) => (r[o] = r[i1] === r[i2] ? 1 : 0), }; -let numbers = arr => arr.map(Number); +const numbers = arr => arr.map(Number); function parseSamples(input) { let samples = input.split("\n\n\n\n")[0].split("\n\n"); diff --git a/src/2018/day19.js b/src/2018/day19.js index 5aac2309..4edaf462 100644 --- a/src/2018/day19.js +++ b/src/2018/day19.js @@ -1,6 +1,6 @@ import { divisors } from "../utils/divisors.js"; -let ops = { +const ops = { addr: (r, i1, i2, o) => (r[o] = r[i1] + r[i2]), addi: (r, i1, i2, o) => (r[o] = r[i1] + i2), mulr: (r, i1, i2, o) => (r[o] = r[i1] * r[i2]), @@ -18,7 +18,7 @@ let ops = { eqri: (r, i1, i2, o) => (r[o] = r[i1] === i2 ? 1 : 0), eqrr: (r, i1, i2, o) => (r[o] = r[i1] === r[i2] ? 1 : 0), }; -let numbers = arr => arr.map(Number); +const numbers = arr => arr.map(Number); export function part1(input, reg0 = 0) { let lines = input.split("\n"); diff --git a/src/2018/day20.js b/src/2018/day20.js index 1ada9e45..86a8f5de 100644 --- a/src/2018/day20.js +++ b/src/2018/day20.js @@ -1,11 +1,11 @@ -let walk = { +const walk = { W: ({ x, y }) => ({ x: x - 1, y: y + 0 }), E: ({ x, y }) => ({ x: x + 1, y: y + 0 }), N: ({ x, y }) => ({ x: x + 0, y: y - 1 }), S: ({ x, y }) => ({ x: x + 0, y: y + 1 }), }; -let pos = ({ x, y }) => `${x},${y}`; -let unique = arr => +const pos = ({ x, y }) => `${x},${y}`; +const unique = arr => arr .reduce((all, p) => all.concat(p), []) .sort((a, b) => a.x - b.x || a.y - b.y) diff --git a/src/2018/day21.js b/src/2018/day21.js index 8bac6207..9e372a68 100644 --- a/src/2018/day21.js +++ b/src/2018/day21.js @@ -1,4 +1,4 @@ -let ops = { +const ops = { addr: (l, i1, i2, o) => `case ${l}: r${o} = r${i1} + r${i2}; break;`, addi: (l, i1, i2, o) => `case ${l}: r${o} = r${i1} + ${i2}; break;`, mulr: (l, i1, i2, o) => `case ${l}: r${o} = r${i1} * r${i2}; break;`, diff --git a/src/2018/day22.js b/src/2018/day22.js index 95c95380..c7444b5c 100644 --- a/src/2018/day22.js +++ b/src/2018/day22.js @@ -1,6 +1,6 @@ let cache = {}; -let pos = ({ x, y }) => `${x},${y}`; -let terrain = (point, depth) => erosion(point, depth) % 3; +const pos = ({ x, y }) => `${x},${y}`; +const terrain = (point, depth) => erosion(point, depth) % 3; function erosion({ x, y }, depth) { let geo; diff --git a/src/2019/day11.js b/src/2019/day11.js index 35b9636b..78044b20 100644 --- a/src/2019/day11.js +++ b/src/2019/day11.js @@ -2,7 +2,7 @@ import { execute } from "./day09.js"; import { ocr } from "../utils/ocr.js"; function move({ x, y }, direction) { - let directions = { + const directions = { "^": { x, y: y - 1 }, "v": { x, y: y + 1 }, "<": { x: x - 1, y }, @@ -11,14 +11,14 @@ function move({ x, y }, direction) { return directions[direction]; } -let left = { +const left = { "^": "<", "<": "v", "v": ">", ">": "^", }; -let right = { +const right = { "^": ">", ">": "v", "v": "<",