From c8b225899462d82d66ca7d8032447ed62c1528a8 Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 10 Dec 2022 21:49:42 +0100 Subject: [PATCH] day 10, prettier and a awk solution for part 2 --- d10/part2.awk | 20 ++++++++++++++++++++ d10/part2.py | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 d10/part2.awk diff --git a/d10/part2.awk b/d10/part2.awk new file mode 100644 index 0000000..a58678f --- /dev/null +++ b/d10/part2.awk @@ -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 + } +} \ No newline at end of file diff --git a/d10/part2.py b/d10/part2.py index fe6f499..2f568a1 100644 --- a/d10/part2.py +++ b/d10/part2.py @@ -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]