Skip to content

Commit

Permalink
moving to let instead of const
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed May 6, 2024
1 parent cf737d1 commit e43109a
Show file tree
Hide file tree
Showing 263 changed files with 488 additions and 474 deletions.
2 changes: 1 addition & 1 deletion src/2015/day01.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day01.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day01 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day02.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day02.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day02 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day03.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day03.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day03 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day04.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day04.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day04 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day05.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day05.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day05 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day06.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day06.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day06 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day07.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day07.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day07 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day08.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day08.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day08 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day09.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day09.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day09 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day10.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day10.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day10 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day11.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day11.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day11 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day12.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day12.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day12 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day13.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day13.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day13 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day14.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day14.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day14 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day15.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { day } from './day15.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day15 2015', () => {
test('it should work for example', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day16.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day16.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day16 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day17.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { day } from './day17.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day17 2015', () => {
test('it should work for example', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day18.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day18.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day18 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day19.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day19.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day19 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day20.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { day } from './day20.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day20 2015', () => {
describe('part1', () => {
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() {
const items = {
let 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/day21.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day21.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day21 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day22.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day22.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day22 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day23.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day23.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day23 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day24.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day24.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day24 2015', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day25.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day25.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day25 2015', () => {
describe('part1', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/2016/day01.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ const directions = [
{ y: -1, x: 0 },
{ y: 0, x: -1 },
];

export function day(input) {
const destination = input
let destination = input
.split(', ')
.map(x => {
const [, turn, count] = x.match(/^(R|L)(\d+)$/);
let [, turn, count] = x.match(/^(R|L)(\d+)$/);
return { turn: turn === 'R' ? 1 : -1, count: +count };
})
.reduce(
(state, next) => {
const direction =
let direction =
(state.direction + next.turn + directions.length) % directions.length;
return new Array(next.count).fill().reduce(state => {
const x = state.x + directions[direction].x;
const y = state.y + directions[direction].y;
let x = state.x + directions[direction].x;
let y = state.y + directions[direction].y;
if (state.history[`${x},${y}`]) {
state.twice = state.twice || { x, y };
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day01.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { day } from './day01.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day01 2016', () => {
describe('part1', () => {
Expand Down
28 changes: 15 additions & 13 deletions src/2016/day02.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const directions = {
};

function move(keypad, position, step) {
const next = { x: position.x + step.x, y: position.y + step.y };
let next = { x: position.x + step.x, y: position.y + step.y };
return keypad[next.y] && keypad[next.y][next.x] ? next : position;
}

Expand All @@ -28,22 +28,24 @@ function solve(input, keypad, start) {
.join('');
}

const keypad1 = [
['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
];

export function part1(input) {
const keypad1 = [
['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
];
return solve(input, keypad1, { x: 1, y: 1 });
}

const keypad2 = [
[NaN, NaN, '1', NaN, NaN],
[NaN, '2', '3', '4', NaN],
['5', '6', '7', '8', '9'],
[NaN, 'A', 'B', 'C', NaN],
[NaN, NaN, 'D', NaN, NaN],
];

export function part2(input) {
const keypad2 = [
[NaN, NaN, '1', NaN, NaN],
[NaN, '2', '3', '4', NaN],
['5', '6', '7', '8', '9'],
[NaN, 'A', 'B', 'C', NaN],
[NaN, NaN, 'D', NaN, NaN],
];
return solve(input, keypad2, { x: 0, y: 2 });
}
2 changes: 1 addition & 1 deletion src/2016/day02.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day02.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day02 2016', () => {
describe('part1', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day03.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day03.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day03 2016', () => {
describe('part1', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/2016/day04.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function parseRoom(s) {
const [, name, sector, checksum] = s.match(/^(.*)-(\d+)\[(.*)\]$/);
let [, name, sector, checksum] = s.match(/^(.*)-(\d+)\[(.*)\]$/);
return { name, sector: +sector, checksum };
}

function checksum(s) {
const occurrences = s
let occurrences = s
.replace(/-/g, '')
.split('')
.sort()
Expand Down Expand Up @@ -48,13 +48,13 @@ function parse(input) {
}

export function part1(input) {
const rooms = parse(input);
let rooms = parse(input);
return rooms.reduce((sum, room) => sum + room.sector, 0);
}

export function part2(input) {
const rooms = parse(input);
const room = rooms
let rooms = parse(input);
let room = rooms
.map(room => decrypt(room.name, room.sector))
.findIndex(x => x === 'northpole object storage');
return rooms[room] && rooms[room].sector;
Expand Down
2 changes: 1 addition & 1 deletion src/2016/day04.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { part1, part2 } from './day04.js';
import readInput from '../utils/read-input.js';

const input = readInput(import.meta.url);
let input = readInput(import.meta.url);

describe('day04 2016', () => {
describe('part1', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/2016/day05.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ export function day(input) {
let hash,
count = 0;
let password1 = '';
const password2 = [];
let password2 = [];
let index = -1;
while (count < 8) {
do {
index++;
hash = md5(input + index);
} while (!hash.startsWith('00000'));

const i = +hash[5];
let i = +hash[5];
password1 += hash[5];
if (i >= 0 && i <= 7 && !password2[i]) {
password2[i] = hash[6];
Expand Down
Loading

0 comments on commit e43109a

Please sign in to comment.