From b57e8e30e806fa1af0be1481f4ea2d5551b8ceb1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 19 May 2025 01:18:17 +0100 Subject: [PATCH] 2016: d06: ex1: add solution --- 2016/d06/ex1/ex1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 2016/d06/ex1/ex1.py diff --git a/2016/d06/ex1/ex1.py b/2016/d06/ex1/ex1.py new file mode 100755 index 0000000..b4b854c --- /dev/null +++ b/2016/d06/ex1/ex1.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import collections +import sys + + +def solve(input: str) -> str: + def error_correct(messages: list[str]) -> str: + res: list[str] = [] + for i in range(len(messages[0])): + res.append(collections.Counter(l[i] for l in messages).most_common()[0][0]) + return "".join(res) + + messages = input.splitlines() + return error_correct(messages) + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()