-
Notifications
You must be signed in to change notification settings - Fork 0
/
03.ts
46 lines (42 loc) · 1019 Bytes
/
03.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
import {loadData} from '../shared/utils';
const getHouses = (input: string, houses: Set<string>) => {
let house = [0, 0];
input.split('').forEach(dir => {
switch (dir) {
case '^':
house[1]--;
break;
case '<':
house[0]--;
break;
case '>':
house[0]++;
break;
case 'v':
house[1]++;
break;
}
houses.add(house.join('|'));
});
};
export const part1 = (input: string): number => {
const houses = new Set(['0|0']);
getHouses(input, houses);
return houses.size;
};
export const part2 = (input: string): number => {
const houses = new Set(['0|0']);
const santa = input
.split('')
.filter((_, index) => index % 2 == 0)
.join('');
const roboSanta = input
.split('')
.filter((_, index) => index % 2 == 1)
.join('');
getHouses(santa, houses);
getHouses(roboSanta, houses);
return houses.size;
};
/* istanbul ignore next */
export const parse = async () => await loadData(2015, 3);