aboutsummaryrefslogtreecommitdiff
path: root/2021/13/puzzles.awk
blob: 8c149d73b9f3d69dc6bb46c840805ce2880ff4c9 (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
#!/usr/bin/env -S awk -f

BEGIN           { FS = ",|=" }
/[0-9]+,[0-9]+/ { grid[$2][$1] = 1 }

# START PART 1
flag == 1 { next }
# END PART 1

/x|y/ {
	for (y in grid) {
		for (x in grid[y]) {
			if ($1 ~ /x/ && x * 1 > $2) {
				delete grid[y][x]
				grid[y][$2 - (x - $2)] = 1
			} else if ($1 ~ /y/ && y * 1 > $2) {
				delete grid[y][x]
				grid[$2 - (y - $2)][x] = 1
			}
		}
	}
	# START PART 1
	flag = 1
	# END PART 1
}

END {
	# START PART 1
	for (y in grid) {
		for (x in grid[y])
			acc += grid[y][x]
	}
	print acc
	# END PART 1 START PART 2
	for (y = 0; y < 6; y++) {
		for (x = 0; x < 29; x++)
			printf grid[y][x] ? "█" : " "
		print ""
	}
	# END PART 2
}