summaryrefslogtreecommitdiffstats
path: root/solutions/py/d08.py
diff options
context:
space:
mode:
Diffstat (limited to 'solutions/py/d08.py')
-rw-r--r--solutions/py/d08.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/solutions/py/d08.py b/solutions/py/d08.py
new file mode 100644
index 0000000..659bc3a
--- /dev/null
+++ b/solutions/py/d08.py
@@ -0,0 +1,31 @@
+def count(layer, num):
+ return sum([row.count(num) for row in layer])
+
+
+def pt1(input):
+ img = []
+ least_zeroes = 150 # max
+ n = 0
+ for l in range(100):
+ #print("l", l)
+ layer = [[int(input[0][l*25*6 + y*25 + x]) for x in range(25)] for y in range(6)]
+ if count(layer, 0) < least_zeroes:
+ least_zeroes = count(layer, 0)
+ n = count(layer, 1) * count(layer, 2)
+ img.append(layer)
+ return n
+
+def pt2(input):
+ img = [[[int(input[0][l*25*6 + y*25 + x]) for x in range(25)] for y in range(6)] for l in range(100)]
+ result = img[0]
+ for layer in img[1:]:
+ for x in range(25):
+ for y in range(6):
+ if result[y][x] == 2:
+ result[y][x] = layer[y][x]
+ str_res = []
+ for row in result:
+ for c in row:
+ str_res.append('\u2588' if c == 1 else ' ')
+ str_res.append("\n")
+ return "\n" + ("".join(str_res))