day 6
This commit is contained in:
parent
471be2c493
commit
999e63ec22
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@ node_modules
|
|||||||
.pls_cache/
|
.pls_cache/
|
||||||
.perl-version
|
.perl-version
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
*_BACKUP_*
|
||||||
|
*_BASE_*
|
||||||
|
*_LOCAL_*
|
||||||
|
*_REMOTE_*
|
||||||
|
22
2022/06/part1.js
Normal file
22
2022/06/part1.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import * as R from "remeda";
|
||||||
|
import { readFile } from "../05/part1.js";
|
||||||
|
|
||||||
|
export const puzzleInput = readFile(import.meta.url, "input");
|
||||||
|
|
||||||
|
export default function (code) {
|
||||||
|
const size = 4;
|
||||||
|
let index = size;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (
|
||||||
|
R.pipe(
|
||||||
|
code,
|
||||||
|
(c) => c.substr(index - size, size).split(""),
|
||||||
|
R.uniq,
|
||||||
|
(c) => c.length
|
||||||
|
) === size
|
||||||
|
)
|
||||||
|
return index;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
19
2022/06/part2.js
Normal file
19
2022/06/part2.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import * as R from "remeda";
|
||||||
|
|
||||||
|
export default function (code) {
|
||||||
|
const size = 14;
|
||||||
|
let index = size;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (
|
||||||
|
R.pipe(
|
||||||
|
code,
|
||||||
|
(c) => c.substr(index - size, size).split(""),
|
||||||
|
R.uniq,
|
||||||
|
(c) => c.length
|
||||||
|
) === size
|
||||||
|
)
|
||||||
|
return index;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
37
2022/06/test.js
Normal file
37
2022/06/test.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { test, expect, describe } from "vitest";
|
||||||
|
|
||||||
|
import { expectSolution } from "../01/main.js";
|
||||||
|
import part1, { puzzleInput } from "./part1.js";
|
||||||
|
import part2 from "./part2.js";
|
||||||
|
|
||||||
|
describe("part 1", () => {
|
||||||
|
test("samples", () => {
|
||||||
|
expect(part1("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(7);
|
||||||
|
|
||||||
|
Object.entries({
|
||||||
|
bvwbjplbgvbhsrlpgdmjqwftvncz: 5,
|
||||||
|
nppdvjthqldpwncqszvftbrmjlhg: 6,
|
||||||
|
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 10,
|
||||||
|
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 11,
|
||||||
|
}).forEach(([code, index]) => expect(part1(code)).toEqual(index));
|
||||||
|
});
|
||||||
|
test("solution", () => {
|
||||||
|
expectSolution(part1(puzzleInput)).toEqual(1640);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("part 2", () => {
|
||||||
|
test("samples", () => {
|
||||||
|
expect(part2("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(19);
|
||||||
|
|
||||||
|
Object.entries({
|
||||||
|
bvwbjplbgvbhsrlpgdmjqwftvncz: 23,
|
||||||
|
nppdvjthqldpwncqszvftbrmjlhg: 23,
|
||||||
|
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 29,
|
||||||
|
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 26,
|
||||||
|
}).forEach(([code, index]) => expect(part2(code)).toEqual(index));
|
||||||
|
});
|
||||||
|
test("solution", () => {
|
||||||
|
expectSolution(part2(puzzleInput)).toEqual(3613);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user