aboutsummaryrefslogtreecommitdiff
path: root/2023/12
diff options
context:
space:
mode:
authorMarvin Borner2023-12-12 11:51:43 +0100
committerMarvin Borner2023-12-12 11:51:43 +0100
commit49f1df9dc23f7e1e25a1fa9978c0ad9f3b169320 (patch)
tree4f89062068439fc821321c79e2e2a25d8cdbd36a /2023/12
parent5bf9d5a88389ef8285375f1c98c24c6d5904e2a7 (diff)
Initial group approach
Diffstat (limited to '2023/12')
-rw-r--r--2023/12/solve.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/2023/12/solve.py b/2023/12/solve.py
new file mode 100644
index 0000000..bd9da6d
--- /dev/null
+++ b/2023/12/solve.py
@@ -0,0 +1,43 @@
+L = [
+ (p := l.strip().split(" ")) and (p[0], [int(n) for n in p[1].split(",")])
+ for l in open("input").readlines()
+]
+
+
+def groups(pat):
+ gs = []
+ c = []
+ for p in pat:
+ if p in "#?":
+ c.append(p)
+ elif c:
+ gs.append(c)
+ c = []
+ return gs[::-1]
+
+
+def arrangements(pat, sol):
+ arr = 1
+
+ gs = groups(pat)
+ for i, g in enumerate(gs):
+ if len(g) == sol[0]: # ???.[#??] 1,1,[3]
+ del sol[0]
+ continue
+ if g.count("#") == 0:
+ if len(g) == len(sol) + 1 and len(sol) == sum(sol): # [???].### [1,1],3
+ break
+ # if len(g) > len(sol)
+ print(g, sol)
+
+ return arr
+
+
+def part1():
+ res = 0
+ for pat, sol in L:
+ res += arrangements(f".{pat}.", sol[::-1])
+ print(res)
+
+
+part1()