about summary refs log tree commit diff
path: root/aoc/2022/10/part-two.awk
blob: 9126306eace30014690bb248624c65485cbee4c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env -S awk -f
function cycle (c, x) {
  printf x - 2 < c && c < x + 2 ? "#" : "."
  printf c == 39 ? "\n" : ""
  return (c + 1) % 40
}
BEGIN { x = 1 }
{ c = cycle(c, x) }
/^addx/ { c = cycle(c, x) }
{ x += $2 }