summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/12
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-17 23:17:03 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-17 23:17:03 +0100
commitb0324289066876915efb84a133eca039d8e8c8ee (patch)
tree76b06718de422ed0e5aacbd76c611ee4f82ff526 /prog/aoc/23/12
parentaoc11 (diff)
downloadr-b0324289066876915efb84a133eca039d8e8c8ee.tar
r-b0324289066876915efb84a133eca039d8e8c8ee.tar.gz
r-b0324289066876915efb84a133eca039d8e8c8ee.tar.bz2
r-b0324289066876915efb84a133eca039d8e8c8ee.tar.lz
r-b0324289066876915efb84a133eca039d8e8c8ee.tar.xz
r-b0324289066876915efb84a133eca039d8e8c8ee.tar.zst
r-b0324289066876915efb84a133eca039d8e8c8ee.zip
Diffstat (limited to 'prog/aoc/23/12')
-rwxr-xr-xprog/aoc/23/12/1.py53
-rw-r--r--prog/aoc/23/12/correct.txt6
-rw-r--r--prog/aoc/23/12/in.txt6
3 files changed, 65 insertions, 0 deletions
diff --git a/prog/aoc/23/12/1.py b/prog/aoc/23/12/1.py
new file mode 100755
index 0000000..7e07935
--- /dev/null
+++ b/prog/aoc/23/12/1.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python3
+springs = []
+try:
+ while True:
+ s = input()
+ springs.append((s.split(" ")[0], list(map(int, s.split(" ")[1].split(",")))))
+except EOFError:
+ pass
+def counts(vhod):
+ s = vhod + "$"
+ prev = None
+ r = []
+ run = 0
+ for c in s:
+ if prev == None:
+ prev = c
+ run = 1
+ continue
+ if c == prev:
+ run += 1
+ continue
+ if prev == "#":
+ r.append(run)
+ prev = c
+ run = 1
+ return r
+"""
+for spring in springs:
+ print(counts(spring[0]), spring[1])
+"""
+def possibilities(x):
+ r = 0
+ countq = x[0].count("?")
+ for bits in range(2**countq):
+ copy = x[0]
+ for i in range(countq):
+ if bits & (1 << i):
+ copy = copy.replace("?", ".", 1)
+ else:
+ copy = copy.replace("?", "#", 1)
+ if counts(copy) == x[1]:
+ r += 1
+ return r
+def possibilities_serial(array):
+ s = 0
+ for element in array:
+ s += possibilities(element)
+ return s
+batch_size = 10
+batches = [springs[x:x+batch_size] for x in range(0, len(springs), batch_size)]
+from multiprocessing import Pool
+with Pool(len(batches)) as p:
+ print(sum(p.map(possibilities_serial, batches)))
diff --git a/prog/aoc/23/12/correct.txt b/prog/aoc/23/12/correct.txt
new file mode 100644
index 0000000..e2bdf5e
--- /dev/null
+++ b/prog/aoc/23/12/correct.txt
@@ -0,0 +1,6 @@
+#.#.### 1,1,3
+.#...#....###. 1,1,3
+.#.###.#.###### 1,3,1,6
+####.#...#... 4,1,1
+#....######..#####. 1,6,5
+.###.##....# 3,2,1
diff --git a/prog/aoc/23/12/in.txt b/prog/aoc/23/12/in.txt
new file mode 100644
index 0000000..e925935
--- /dev/null
+++ b/prog/aoc/23/12/in.txt
@@ -0,0 +1,6 @@
+???.### 1,1,3
+.??..??...?##. 1,1,3
+?#?#?#?#?#?#?#? 1,3,1,6
+????.#...#... 4,1,1
+????.######..#####. 1,6,5
+?###???????? 3,2,1