-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.ts
33 lines (29 loc) · 933 Bytes
/
06.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
import { getFileContent } from "./utils.js";
const isDifferent = (str: string, startIndex: number, count: number = 4) => {
const arr = str.split("").slice(startIndex, startIndex + count);
if (arr.length === new Set(arr).size) return true;
return false;
};
const first = (str: string) => {
for (let i = 0; i < str.length - 4; i++) {
if (isDifferent(str, i)) {
const result = i + 4;
console.log(result);
return result;
}
}
return -1;
};
const second = (str: string) => {
for (let i = 0; i < str.length - 14; i++) {
if (isDifferent(str, i, 14)) {
const result = i + 14;
console.log(result);
return result;
}
}
return -1;
};
const data = getFileContent("input.txt");
console.assert(first(data) === 1582, "Not matching first part");
console.assert(second(data) === 3588, "Not matching second part");