-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09.js
56 lines (52 loc) · 1.35 KB
/
day09.js
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
49
50
51
52
53
54
55
56
console.log('###########');
import { readLines } from 'https://deno.land/[email protected]/io/bufio.ts';
import { range } from 'https://deno.land/x/[email protected]/range.mjs';
import { slidingWindows } from 'https://deno.land/[email protected]/collections/mod.ts';
import count from 'https://deno.land/x/[email protected]/src/collection/count.ts';
let input = await Deno.readTextFile('./resources/input09.txt');
//input = await Deno.readTextFile('./resources/input09_demo.txt');
const moves = input
.trim()
.split('\n')
.map((s) => s.trim().split(' '))
.map(([a, b]) => [a, parseInt(b, 10)]);
const dist = (a, b) => {};
let T = [0, 0],
H = [0, 0];
let map = {};
for (let [d, v] of moves) {
console.log({ d, v });
for (let i = 0; i < v; i++) {
if (d === 'U') {
H[1]++;
if (H[1] - T[1] > 1) {
T[1] = H[1] - 1;
T[0] = H[0];
}
}
if (d === 'D') {
H[1]--;
if (T[1] - H[1] > 1) {
T[1] = H[1] + 1;
T[0] = H[0];
} // T[1]--;
}
if (d === 'L') {
H[0]--;
if (T[0] - H[0] > 1) {
T[0] = H[0] + 1;
T[1] = H[1];
} //T[0]--;
}
if (d === 'R') {
H[0]++;
if (H[0] - T[0] > 1) {
T[0] = H[0] - 1;
T[1] = H[1];
} //T[0]++;
}
console.log({ H, T });
map[`${T[0]}-${T[1]}`] = 1;
}
}
console.log({ map }, Object.keys(map).length);