aboutsummaryrefslogtreecommitdiff
path: root/2022/10/puzzle-2.awk
blob: 31a9ea68b7b8a69f0b8dfef376314a7c139363e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/awk -f

BEGIN { x = 1 }

{
	for (i = 0; i < ($1 == "addx" ? 2 : 1); i++) {
		p = (++c % 40) - 1
		if (p == -1)
			p = 39
		printf (p == x - 1 || p == x || p == x + 1) ? "█" : " "
		if (p == 39)
			print ""
	}
}
/addx/ { x += $2 }