day 10, prettier and a awk solution for part 2

This commit is contained in:
setop 2022-12-10 21:49:42 +01:00
parent 38a377ac84
commit c8b2258994
2 changed files with 22 additions and 2 deletions

20
d10/part2.awk Normal file
View File

@ -0,0 +1,20 @@
BEGIN { x=1 }
function inc() {
i = (c%40)
A[c+1] = (i==x-1||i==x||i==x+1) ? "█" : "░"
c+=1
}
{ inc() }
$1 == "addx" {
inc()
x+=$2
}
END {
for (i=0;i<=5;i++) {
r = ""
for (j=1;j<=40;j++) {
r = r A[i*40+j]
}
print r
}
}

View File

@ -2,14 +2,14 @@ import sys
X = 1
C = 0
LCD = [["."]*40 for _ in range(6)]
LCD = [[""]*40 for _ in range(6)]
def inc():
global C
(r,c) = divmod(C, 40)
C+=1
if c in [X, X-1, X+1]:
LCD[r][c]="#"
LCD[r][c]=""
for l in sys.stdin.read().splitlines():
m, q = (l+" _").split(" ")[:2]