Skip to content

Commit ec28584

Browse files
committed
moving to let
1 parent 4cab7a0 commit ec28584

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

src/2015/day03.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function step(x, y) {
22
return pos => ({ x: pos.x + x, y: pos.y + y });
33
}
44

5-
let steps = {
5+
const steps = {
66
"<": step(-1, 0),
77
">": step(1, 0),
88
"^": step(0, -1),

src/2015/day07.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let ops = {
1+
const ops = {
22
AND: (p1, p2) => (2 ** 16 + (p1 & p2)) % 2 ** 16,
33
OR: (p1, p2) => (2 ** 16 + (p1 | p2)) % 2 ** 16,
44
NOT: (p1, p2) => (2 ** 16 + ~p2) % 2 ** 16,

src/2016/day08.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function rect(state, x, y) {
1414
}
1515

1616
function rotateRow(state, x, y) {
17-
const moved = state[y].splice(-x, x);
17+
let moved = state[y].splice(-x, x);
1818
state[y] = moved.concat(state[y]);
1919
return state;
2020
}
@@ -33,32 +33,32 @@ function flatten(screen) {
3333

3434
function parseCommand(command) {
3535
if (command.startsWith("rect")) {
36-
const [, x, y] = command.match(/^rect (\d+)x(\d+)$/);
36+
let [, x, y] = command.match(/^rect (\d+)x(\d+)$/);
3737
return state => rect(state, +x, +y);
3838
} else if (command.startsWith("rotate row")) {
39-
const [, y, x] = command.match(/^rotate row y=(\d+) by (\d+)$/);
39+
let [, y, x] = command.match(/^rotate row y=(\d+) by (\d+)$/);
4040
return state => rotateRow(state, +x, +y);
4141
} else if (command.startsWith("rotate column")) {
42-
const [, x, y] = command.match(/^rotate column x=(\d+) by (\d+)$/);
42+
let [, x, y] = command.match(/^rotate column x=(\d+) by (\d+)$/);
4343
return state => rotateColumn(state, +x, +y);
4444
}
4545
}
4646

4747
function solve(input, width, height) {
48-
const screen = init(width, height);
48+
let screen = init(width, height);
4949
return input
5050
.split("\n")
5151
.map(parseCommand)
5252
.reduce((state, fn) => fn(state), screen);
5353
}
5454

5555
export function part1(input, width = 50, height = 6) {
56-
const final = solve(input, width, height);
56+
let final = solve(input, width, height);
5757
return flatten(final).filter(x => x).length;
5858
}
5959

6060
export function part2(input, width = 50, height = 6) {
61-
const final = solve(input, width, height);
61+
let final = solve(input, width, height);
6262
return ocr(
6363
final.map(row => `${row.map(x => (x ? "#" : ".")).join("")}`).join("\n"),
6464
);

src/2016/day09.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function decodeLength(s, v2) {
2-
const [, prefix, lengthStr, timesStr, rest] = s.match(
2+
let [, prefix, lengthStr, timesStr, rest] = s.match(
33
/^([^(]*)(?:\((\d+)x(\d+)\))?(.*)$/,
44
);
55
if (lengthStr) {
6-
const length = +lengthStr;
7-
const times = +timesStr;
8-
const repeat =
6+
let length = +lengthStr;
7+
let times = +timesStr;
8+
let repeat =
99
times * (v2 ? decodeLength(rest.slice(0, length), v2) : length);
1010
return prefix.length + repeat + decodeLength(rest.slice(length), v2);
1111
} else {

src/2016/day10.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export function day(input, low = 17, high = 61) {
1717
}
1818

1919
function parse(line) {
20-
const match = line.match(
20+
let match = line.match(
2121
/^bot (\d+) gives low to (bot|output) (\d+) and high to (bot|output) (\d+)$/,
2222
);
23-
const [, bot, lowDest, lowIndex, highDest, highIndex] = match;
23+
let [, bot, lowDest, lowIndex, highDest, highIndex] = match;
2424
return state => {
2525
if (state.bots[bot] && state.bots[bot].length === 2) {
2626
state = assign(state, `${lowDest}s`, +lowIndex, state.bots[bot][0]);
@@ -34,20 +34,20 @@ export function day(input, low = 17, high = 61) {
3434
function init(lines) {
3535
return lines.reduce(
3636
(state, line) => {
37-
const [, value, bot] = line.match(/^value (\d+) goes to bot (\d+)$/);
37+
let [, value, bot] = line.match(/^value (\d+) goes to bot (\d+)$/);
3838
return assign(state, "bots", +bot, +value);
3939
},
4040
{ bots: {}, outputs: {} },
4141
);
4242
}
4343

44-
const lines = input.split("\n");
45-
const state = init(lines.filter(x => x.startsWith("value")));
46-
const instructions = lines.filter(x => x.startsWith("bot")).map(parse);
44+
let lines = input.split("\n");
45+
let state = init(lines.filter(x => x.startsWith("value")));
46+
let instructions = lines.filter(x => x.startsWith("bot")).map(parse);
4747
while (instructions.some(update => update(state))) {
4848
/**/
4949
}
5050

51-
const part2 = state.outputs[0] * state.outputs[1] * state.outputs[2];
51+
let part2 = state.outputs[0] * state.outputs[1] * state.outputs[2];
5252
return { part1, part2 };
5353
}

src/2016/day11.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { combinations } from "combinatorial-generators";
22

33
function parse(input) {
44
let pieces = [];
5-
const state = {
5+
let state = {
66
elevator: 0,
77
floors: input.split("\n").map(x => {
8-
const generators = x.match(/[^\s]+(?=\s*generator)/g) || [];
9-
const microchips = x.match(/[^\s]+(?=-compatible microchip)/g) || [];
8+
let generators = x.match(/[^\s]+(?=\s*generator)/g) || [];
9+
let microchips = x.match(/[^\s]+(?=-compatible microchip)/g) || [];
1010
pieces = pieces.concat(generators).concat(microchips);
1111
return { generators, microchips };
1212
}),
@@ -59,8 +59,8 @@ function legal(state) {
5959
}
6060

6161
function getMoves(state, diff) {
62-
const src = state.floors[state.elevator];
63-
const pairs = src.generators.filter(x => src.microchips.includes(x));
62+
let src = state.floors[state.elevator];
63+
let pairs = src.generators.filter(x => src.microchips.includes(x));
6464
return pairs
6565
.map(x => ({ generators: [x], microchips: [x] }))
6666
.concat(
@@ -91,7 +91,7 @@ function getNeighbors(state) {
9191
}
9292

9393
function done(state) {
94-
const { generators, microchips } = state.floors.at(-1);
94+
let { generators, microchips } = state.floors.at(-1);
9595
return state.pieces.length === generators.length + microchips.length;
9696
}
9797

@@ -136,15 +136,13 @@ function stringify({ elevator, floors }) {
136136
}
137137

138138
function solve(state) {
139-
const queue = [{ distance: 0, state, path: [state] }];
140-
const visited = new Set().add(stringify(state));
139+
let queue = [{ distance: 0, state, path: [state] }];
140+
let visited = new Set().add(stringify(state));
141141
while (queue.length > 0) {
142-
const { state, distance, path } = queue.shift();
143-
const neighbors = getNeighbors(state).filter(
144-
x => !visited.has(stringify(x)),
145-
);
146-
for (const x of neighbors) {
147-
const json = stringify(x);
142+
let { state, distance, path } = queue.shift();
143+
let neighbors = getNeighbors(state).filter(x => !visited.has(stringify(x)));
144+
for (let x of neighbors) {
145+
let json = stringify(x);
148146
if (done(x)) {
149147
// path.concat(x).forEach(state => console.log(print(state), '\n----------------------'));
150148
return distance + 1;
@@ -161,7 +159,7 @@ export function part1(input) {
161159
}
162160

163161
export function part2(input) {
164-
const state = parse(input);
162+
let state = parse(input);
165163
state.floors[0].generators.push("elerium", "dilithium");
166164
state.floors[0].microchips.push("elerium", "dilithium");
167165
state.pieces.push("elerium", "dilithium", "elerium", "dilithium");

src/2024/day06.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let step = {
1+
const step = {
22
up: { x: 0, y: -1, turn: "right" },
33
down: { x: 0, y: 1, turn: "left" },
44
left: { x: -1, y: 0, turn: "up" },

0 commit comments

Comments
 (0)