-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
38 lines (34 loc) · 877 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import run from "aocrunner"
import { flip, pair, pipe, reduce, reduced, split, takeLast, uniq } from "ramda"
import { mapIndexed } from "../utils/index.js"
const parseInput = pipe(split(""), mapIndexed(flip(pair)))
const findMarker =
(length: number) =>
(acc: [string[]], [idx, char]: [number, string]) => {
const next = takeLast(length, [...acc, char])
return uniq(next).length === length ? reduced(idx + 1) : next
}
const part1 = pipe(parseInput, reduce(findMarker(4), []))
const part2 = pipe(parseInput, reduce(findMarker(14), []))
run({
part1: {
tests: [
{
input: `mjqjpqmgbljsphdztnvjfqwrcgsmlb`,
expected: 7,
},
],
solution: part1,
},
part2: {
tests: [
// {
// input: ``,
// expected: "",
// },
],
solution: part2,
},
trimTestInputs: true,
onlyTests: false,
})