aoc

commit 6f8d4d6961731dd934f63132d520ce112165f291

Author: Honza Pokorny <me@honza.ca>

8p2

 008/main.py | 43 +++++++++++++++++++++++++++++++------------


diff --git a/008/main.py b/008/main.py
index a600516788844fbdba7fcdc1791f7b03079e7da5..4392f01fbf853bd3150e4c2da539b24cfb39e143 100644
--- a/008/main.py
+++ b/008/main.py
@@ -1,3 +1,6 @@
+import itertools
+
+
 W = 25
 H = 6
 
@@ -15,23 +18,39 @@
 def main():
     data = open('input').read()
     layers = get_layers(data)
-    x = {}
 
-    for layer in layers:
-        assert len(layer) == W * H
-        zeros = filter(lambda x: x == '0', layer)
-        x[len(list(zeros))] = layer
+    top = layers[0]
+    result = []
 
-    k = list(x.keys())
-    k.sort()
+    for i, d in enumerate(top):
+        if d in ['1', '0']:
+            result.append(d)
+        else:
+            o = None
+            c = 1
+            while True:
+                l = layers[c]
+                candidate = l[i]
+                if candidate == '2':
+                    c += 1
+                    continue
+                else:
+                    result.append(candidate)
+                    break
 
-    smallest = x[k[0]]
-    print(smallest)
+    a = []
 
-    ones = len(list(filter(lambda x: x == '1', smallest)))
-    twos = len(list(filter(lambda x: x == '2', smallest)))
+    for r in result:
+        if r == '1':
+            a.append('😀')
+        else:
+            a.append('🖤')
 
-    print(ones * twos)
+    for x in itertools.count(step=W):
+        if x >= len(result):
+            break
+        row = a[x:x+W]
+        print(''.join(row))
 
 
 if __name__ == '__main__':