Skip to content

Commit

Permalink
some const
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 24, 2024
1 parent e4d0c9b commit 2dc3397
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/2015/day11.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day13.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
4 changes: 2 additions & 2 deletions src/2015/day16.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let expect1 = {
const expect1 = {
id: () => true,
children: 3,
cats: 7,
Expand All @@ -12,7 +12,7 @@ let expect1 = {
perfumes: 1,
};

let expect2 = {
const expect2 = {
...expect1,
cats: x => x > expect1.cats,
trees: x => x > expect1.trees,
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day21.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day22.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let spells = {
const spells = {
Missile: {
mana: 53,
effect: game => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day23.js
Original file line number Diff line number Diff line change
@@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day01.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let directions = [
const directions = [
{ y: 1, x: 0 },
{ y: 0, x: 1 },
{ y: -1, x: 0 },
Expand Down
6 changes: 3 additions & 3 deletions src/2016/day02.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let directions = {
const directions = {
D: { y: 1, x: 0 },
R: { y: 0, x: 1 },
U: { y: -1, x: 0 },
Expand Down Expand Up @@ -28,7 +28,7 @@ function solve(input, keypad, start) {
.join("");
}

let keypad1 = [
const keypad1 = [
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"],
Expand All @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day12.js
Original file line number Diff line number Diff line change
@@ -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]++,
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day20.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let MAX_IP = 4294967295;
const MAX_IP = 4294967295;

function merge(ranges) {
ranges.sort((a, b) => a[0] - b[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/2016/day21.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day23.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let ops = {
const ops = {
cpy: (src, register) => state => {
if (state[register] !== undefined) {
src = state[src] === undefined ? +src : state[src];
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day25.js
Original file line number Diff line number Diff line change
@@ -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]++,
Expand Down
2 changes: 1 addition & 1 deletion src/2017/day18.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion src/2017/day19.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
6 changes: 3 additions & 3 deletions src/2017/day21.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let pattern = [".#.", "..#", "###"];
let permutations2 = [
const pattern = [".#.", "..#", "###"];
const permutations2 = [
[1, 2, 3, 4],
[3, 4, 1, 2],
[1, 3, 2, 4],
Expand All @@ -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],
Expand Down
6 changes: 3 additions & 3 deletions src/2017/day22.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/2018/day05.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/2018/day07.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const abc = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";

function next(prerequisites, done) {
let options = [];
Expand Down
12 changes: 6 additions & 6 deletions src/2018/day13.js
Original file line number Diff line number Diff line change
@@ -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--,
Expand Down
6 changes: 3 additions & 3 deletions src/2018/day15.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/2018/day16.js
Original file line number Diff line number Diff line change
@@ -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]),
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/2018/day19.js
Original file line number Diff line number Diff line change
@@ -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]),
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/2018/day20.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/2018/day21.js
Original file line number Diff line number Diff line change
@@ -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;`,
Expand Down
4 changes: 2 additions & 2 deletions src/2018/day22.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/2019/day11.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -11,14 +11,14 @@ function move({ x, y }, direction) {
return directions[direction];
}

let left = {
const left = {
"^": "<",
"<": "v",
"v": ">",
">": "^",
};

let right = {
const right = {
"^": ">",
">": "v",
"v": "<",
Expand Down

0 comments on commit 2dc3397

Please sign in to comment.