summaryrefslogtreecommitdiff
path: root/13_2023.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
committerJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
commit8e313e2614c7a0fe5af924febdbacc650e33835e (patch)
tree63426b6942ceebe17708140c972a7d7451bd2f74 /13_2023.py
downloadaoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz
aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip
intial
Diffstat (limited to '13_2023.py')
-rw-r--r--13_2023.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/13_2023.py b/13_2023.py
new file mode 100644
index 0000000..780c62b
--- /dev/null
+++ b/13_2023.py
@@ -0,0 +1,39 @@
+import sys
+import re
+from copy import deepcopy
+from math import gcd
+from collections import defaultdict, Counter, deque
+
+D = open(sys.argv[1]).read().strip()
+L = D.split("\n")
+G = [[c for c in row] for row in L]
+
+for part2 in [False, True]:
+ ans = 0
+ for grid in D.split("\n\n"):
+ G = [[c for c in row] for row in grid.split("\n")]
+ R = len(G)
+ C = len(G[0])
+ for c in range(C - 1):
+ badness = 0
+ for dc in range(C):
+ left = c - dc
+ right = c + 1 + dc
+ if 0 <= left < right < C:
+ for r in range(R):
+ if G[r][left] != G[r][right]:
+ badness += 1
+ if badness == (1 if part2 else 0):
+ ans += c + 1
+ for r in range(R - 1):
+ badness = 0
+ for dr in range(R):
+ up = r - dr
+ down = r + 1 + dr
+ if 0 <= up < down < R:
+ for c in range(C):
+ if G[up][c] != G[down][c]:
+ badness += 1
+ if badness == (1 if part2 else 0):
+ ans += 100 * (r + 1)
+ print(ans)