summary refs log tree commit diff homepage
path: root/2022/day09.awk
blob: da142a4c33b75e1cb15ad7250189a16c08425f2e (plain) (blame)
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
BEGIN {
	t1[0,0] = 1;
	t9[0,0] = 1;
}
function abs(x) {
	return (x < 0 ? -x : x);
}
function step(k) {
	rx = kx[k] - kx[k-1];
	ry = ky[k] - ky[k-1];
	if (abs(rx) <= 1 && abs(ry) <= 1) return;
	if (rx == 0) {
		ky[k] += (ry < 0 ? +1 : -1);
	} else if (ry == 0) {
		kx[k] += (rx < 0 ? +1 : -1);
	} else {
		kx[k] += (rx < 0 ? +1 : -1);
		ky[k] += (ry < 0 ? +1 : -1);
	}
}
{
	dx = 0;
	dy = 0;
	if ($1 == "U") dy = -1;
	if ($1 == "D") dy = +1;
	if ($1 == "L") dx = -1;
	if ($1 == "R") dx = +1;
	for (i = 1; i <= $2; ++i) {
		kx[0] += dx;
		ky[0] += dy;
		for (k = 1; k <= 9; ++k) {
			step(k);
		}
		t1[+kx[1],+ky[1]] = 1;
		t9[+kx[9],+ky[9]] = 1;
	}
}
END {
	for (i in t1) {
		sum1++;
	}
	print sum1;
	for (i in t9) {
		sum9++;
	}
	print sum9;
}
d>Remove C code from link scriptJune McEnroe 2017-09-06Move C code to bin, Makefile, AGPLJune McEnroe 2017-09-05Pass final NULL to execlpJune McEnroe 2017-09-05Add watch.cJune McEnroe 2017-09-02Remove Scala highlightingJune McEnroe 2017-08-31Fix Linux console Tarmak 3June McEnroe 2017-08-31Use Tarmak 3 on Linux consoleJune McEnroe 2017-08-25Install ddateJune McEnroe 2017-08-19Move nethack options to envJune McEnroe 2017-08-17Remove scala syntax fileJune McEnroe 2017-08-06Add wakeJune McEnroe 2017-08-04Use $() in install.shJune McEnroe 2017-08-02Create Code Tarmak 3 layoutJune McEnroe 2017-07-31Add tupJune McEnroe 2017-07-31Use designated initializer for hnel tableJune McEnroe 2017-07-30Add juneJune McEnroe 2017-07-30Play nethack as ValkyrieJune McEnroe 2017-07-28Add toggle to hnelJune McEnroe 2017-07-28Install slJune McEnroe 2017-07-25Add up, supJune McEnroe 2017-07-24Autopickup ringsJune McEnroe 2017-07-24Name dogJune McEnroe 2017-07-23Add nethackrcJune McEnroe 2017-07-23Remove useless setuid in briJune McEnroe 2017-07-23Clean up hnel a tiny bitJune McEnroe 2017-07-21Set window size in hnelJune McEnroe 2017-07-21Add hnelJune McEnroe 2017-07-19chmod 600 in dtchJune McEnroe