ref: 3703478dcfedd048437f7a0515dbda2ff8a22d8d
2019/008/main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import itertools W = 25 H = 6 def get_layers(data): layers = [] while len(data): layers.append(data[:W * H]) data = data[W * H:] return layers def main(): data = open('input').read() layers = get_layers(data) top = layers[0] result = [] 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 a = [] for r in result: if r == '1': a.append('😀') else: a.append('🖤') for x in itertools.count(step=W): if x >= len(result): break row = a[x:x+W] print(''.join(row)) if __name__ == '__main__': main() |