From b15c967b8d53a1b95dea52360e9773438e78c043 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 11 Dec 2019 00:22:21 +0100 Subject: [PATCH] 2019: d08: ex2: add solution --- 2019/d08/ex2/ex2.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 2019/d08/ex2/ex2.py diff --git a/2019/d08/ex2/ex2.py b/2019/d08/ex2/ex2.py new file mode 100755 index 0000000..dafe9a5 --- /dev/null +++ b/2019/d08/ex2/ex2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys + + +def main() -> None: + COLUMNS = 25 + ROWS = 6 + digits = [int(d) for d in str(int(sys.stdin.read()))] + + assert len(digits) % (COLUMNS * ROWS) == 0 # Sanity check + LAYERS = int(len(digits) / (COLUMNS * ROWS)) + + layers = [ + [digits.pop(0) for __ in range(COLUMNS) for __ in range(ROWS)] + for __ in range(LAYERS) + ] + + ans = [] + for pixels in zip(*(layer for layer in layers)): + ans.append(next(color for color in pixels if color != 2)) + + print( + "\n".join( + "".join("█" if ans.pop(0) == 0 else " " for __ in range(COLUMNS)) + for __ in range(ROWS) + ) + ) + + +if __name__ == "__main__": + main()