-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (43 loc) · 972 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
39
40
41
42
43
44
45
46
47
48
import run from 'aocrunner'
const parseInput = (rawInput: string) => rawInput.trim().split('')
const findUniqueCharsPosition = (chars: string[], setSize: number) => {
const lastChars: string[] = []
for (let i = 0; i < chars.length; i++) {
lastChars.push(chars[i])
if (lastChars.length > setSize) lastChars.shift()
if (new Set(lastChars).size === setSize) {
return i + 1
}
}
throw 'failed'
}
const part1 = (rawInput: string) => {
const input = parseInput(rawInput)
return findUniqueCharsPosition(input, 4).toString()
}
const part2 = (rawInput: string) => {
const input = parseInput(rawInput)
return findUniqueCharsPosition(input, 14).toString()
}
run({
part1: {
tests: [
{
input: `mjqjpqmgbljsphdztnvjfqwrcgsmlb`,
expected: '7',
},
],
solution: part1,
},
part2: {
tests: [
{
input: `mjqjpqmgbljsphdztnvjfqwrcgsmlb`,
expected: '19',
},
],
solution: part2,
},
trimTestInputs: true,
// onlyTests: true,
})