Skip to content

Commit

Permalink
move to double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Oct 26, 2024
1 parent ed28f76 commit 844d522
Show file tree
Hide file tree
Showing 461 changed files with 7,865 additions and 7,969 deletions.
611 changes: 254 additions & 357 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
]
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"quoteProps": "consistent",
"arrowParens": "avoid"
Expand All @@ -59,4 +58,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/2015/day01.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function parse(input) {
return input.split('').map(x => (x === '(' ? 1 : -1));
return input.split("").map(x => (x === "(" ? 1 : -1));
}

export function part1(input) {
Expand Down
22 changes: 11 additions & 11 deletions src/2015/day01.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { part1, part2 } from './day01.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day01.js";
import readInput from "../utils/read-input.js";

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

describe('day01 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
expect(part1('()()')).toEqual(0);
describe("day01 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(part1("()()")).toEqual(0);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(74);
});
});

describe('part2', () => {
test('it should work for part 2 examples', () => {
expect(part2('()())()')).toEqual(5);
describe("part2", () => {
test("it should work for part 2 examples", () => {
expect(part2("()())()")).toEqual(5);
});

test('it should work for part 2 input', () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(1795);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/2015/day02.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function parse(input) {
return input.split('\n').map(x => x.split('x').map(Number));
return input.split("\n").map(x => x.split("x").map(Number));
}

export function part1(input) {
Expand Down
22 changes: 11 additions & 11 deletions src/2015/day02.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { part1, part2 } from './day02.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day02.js";
import readInput from "../utils/read-input.js";

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

describe('day02 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
expect(part1('2x3x4\n1x1x10')).toEqual(101);
describe("day02 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(part1("2x3x4\n1x1x10")).toEqual(101);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(1588178);
});
});

describe('part2', () => {
test('it should work for part 2 examples', () => {
expect(part2('2x3x4\n1x1x10')).toEqual(48);
describe("part2", () => {
test("it should work for part 2 examples", () => {
expect(part2("2x3x4\n1x1x10")).toEqual(48);
});

test('it should work for part 2 input', () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(3783758);
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/2015/day03.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ function step(x, y) {
}

const steps = {
'<': step(-1, 0),
'>': step(1, 0),
'^': step(0, -1),
'v': step(0, 1),
"<": step(-1, 0),
">": step(1, 0),
"^": step(0, -1),
"v": step(0, 1),
};

function parse(input) {
return input.split('').map(x => steps[x]);
return input.split("").map(x => steps[x]);
}

export function part1(input) {
Expand All @@ -20,20 +20,20 @@ export function part1(input) {
state.visited.add(`${pos.x}-${pos.y}`);
return state;
},
{ visited: new Set().add('0-0'), pos: { x: 0, y: 0 } },
{ visited: new Set().add("0-0"), pos: { x: 0, y: 0 } },
).visited.size;
}

export function part2(input) {
return parse(input).reduce(
(state, next, index) => {
const turn = index % 2 === 0 ? 'santa' : 'robot';
const turn = index % 2 === 0 ? "santa" : "robot";
const pos = (state.pos[turn] = next(state.pos[turn]));
state.visited.add(`${pos.x}-${pos.y}`);
return state;
},
{
visited: new Set().add('0-0'),
visited: new Set().add("0-0"),
pos: { santa: { x: 0, y: 0 }, robot: { x: 0, y: 0 } },
},
).visited.size;
Expand Down
30 changes: 15 additions & 15 deletions src/2015/day03.spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { part1, part2 } from './day03.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day03.js";
import readInput from "../utils/read-input.js";

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

describe('day03 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
expect(part1('>')).toEqual(2);
expect(part1('^>v<')).toEqual(4);
expect(part1('^v^v^v^v^v')).toEqual(2);
describe("day03 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(part1(">")).toEqual(2);
expect(part1("^>v<")).toEqual(4);
expect(part1("^v^v^v^v^v")).toEqual(2);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(2592);
});
});

describe('part2', () => {
test('it should work for part 2 examples', () => {
expect(part2('^v')).toEqual(3);
expect(part2('^>v<')).toEqual(3);
expect(part2('^v^v^v^v^v')).toEqual(11);
describe("part2", () => {
test("it should work for part 2 examples", () => {
expect(part2("^v")).toEqual(3);
expect(part2("^>v<")).toEqual(3);
expect(part2("^v^v^v^v^v")).toEqual(11);
});

test('it should work for part 2 input', () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(2360);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/2015/day04.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import md5 from '../utils/md5.js';
import md5 from "../utils/md5.js";

function solve(input, prefix) {
let result = 1;
Expand All @@ -9,9 +9,9 @@ function solve(input, prefix) {
}

export function part1(input) {
return solve(input, '00000');
return solve(input, "00000");
}

export function part2(input) {
return solve(input, '000000');
return solve(input, "000000");
}
20 changes: 10 additions & 10 deletions src/2015/day04.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { part1, part2 } from './day04.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day04.js";
import readInput from "../utils/read-input.js";

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

describe('day04 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
expect(part1('abcdef')).toEqual(609043);
expect(part1('pqrstuv')).toEqual(1048970);
describe("day04 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(part1("abcdef")).toEqual(609043);
expect(part1("pqrstuv")).toEqual(1048970);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(282749);
});
});

describe('part2', () => {
test('it should work for part 2 input', () => {
describe("part2", () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(9962624);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/2015/day05.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export function part1(input) {
return input
.split('\n')
.split("\n")
.filter(x => (x.match(/[aeiou]/g) || []).length >= 3)
.filter(x => x.match(/([a-z])\1/))
.filter(x => !x.match(/ab|cd|pq|xy/)).length;
}

export function part2(input) {
return input
.split('\n')
.split("\n")
.filter(x => x.match(/([a-z][a-z]).*\1/))
.filter(x => x.match(/([a-z]).\1/)).length;
}
36 changes: 18 additions & 18 deletions src/2015/day05.spec.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { part1, part2 } from './day05.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day05.js";
import readInput from "../utils/read-input.js";

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

describe('day05 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
expect(part1('ugknbfddgicrmopn')).toEqual(1);
expect(part1('aaa')).toEqual(1);
expect(part1('jchzalrnumimnmhp')).toEqual(0);
expect(part1('haegwjzuvuyypxyu')).toEqual(0);
expect(part1('dvszwmarrgswjxmb')).toEqual(0);
describe("day05 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(part1("ugknbfddgicrmopn")).toEqual(1);
expect(part1("aaa")).toEqual(1);
expect(part1("jchzalrnumimnmhp")).toEqual(0);
expect(part1("haegwjzuvuyypxyu")).toEqual(0);
expect(part1("dvszwmarrgswjxmb")).toEqual(0);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(236);
});
});

describe('part2', () => {
test('it should work for part 2 examples', () => {
expect(part2('qjhvhtzxzqqjkmpb')).toEqual(1);
expect(part2('xxyxx')).toEqual(1);
expect(part2('uurcxstgmygtbstg')).toEqual(0);
expect(part2('ieodomkazucvgmuy')).toEqual(0);
describe("part2", () => {
test("it should work for part 2 examples", () => {
expect(part2("qjhvhtzxzqqjkmpb")).toEqual(1);
expect(part2("xxyxx")).toEqual(1);
expect(part2("uurcxstgmygtbstg")).toEqual(0);
expect(part2("ieodomkazucvgmuy")).toEqual(0);
});

test('it should work for part 2 input', () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(51);
});
});
Expand Down
14 changes: 7 additions & 7 deletions src/2015/day06.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function countLights(input, operations) {
return input
.split('\n')
.split("\n")
.map(x => x.match(/^(.*) (\d+),(\d+) through (\d+),(\d+)$/))
.map(x => ({
op: operations[x[1]],
Expand All @@ -23,16 +23,16 @@ function countLights(input, operations) {

export function part1(input) {
return countLights(input, {
'turn on': () => 1,
'turn off': () => 0,
'toggle': val => (val === 0 ? 1 : 0),
"turn on": () => 1,
"turn off": () => 0,
"toggle": val => (val === 0 ? 1 : 0),
});
}

export function part2(input) {
return countLights(input, {
'turn on': val => val + 1,
'turn off': val => Math.max(val - 1, 0),
'toggle': val => val + 2,
"turn on": val => val + 1,
"turn off": val => Math.max(val - 1, 0),
"toggle": val => val + 2,
});
}
30 changes: 15 additions & 15 deletions src/2015/day06.spec.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { part1, part2 } from './day06.js';
import readInput from '../utils/read-input.js';
import { part1, part2 } from "./day06.js";
import readInput from "../utils/read-input.js";

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

describe('day06 2015', () => {
describe('part1', () => {
test('it should work for part 1 examples', () => {
describe("day06 2015", () => {
describe("part1", () => {
test("it should work for part 1 examples", () => {
expect(
part1(
[
'turn on 0,0 through 999,999',
'toggle 0,0 through 999,0',
'turn off 499,499 through 500,500',
].join('\n'),
"turn on 0,0 through 999,999",
"toggle 0,0 through 999,0",
"turn off 499,499 through 500,500",
].join("\n"),
),
).toEqual(1e6 - 1e3 - 4);
});

test('it should work for part 1 input', () => {
test("it should work for part 1 input", () => {
expect(part1(input)).toEqual(400410);
});
});

describe('part2', () => {
test('it should work for part 2 examples', () => {
expect(part2('turn on 0,0 through 0,0')).toEqual(1);
expect(part2('toggle 0,0 through 999,999')).toEqual(2e6);
describe("part2", () => {
test("it should work for part 2 examples", () => {
expect(part2("turn on 0,0 through 0,0")).toEqual(1);
expect(part2("toggle 0,0 through 999,999")).toEqual(2e6);
});

test('it should work for part 2 input', () => {
test("it should work for part 2 input", () => {
expect(part2(input)).toEqual(15343601);
});
});
Expand Down
Loading

0 comments on commit 844d522

Please sign in to comment.