From 06e45ad41b544cb692e6578dfcea873637992729 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sat, 5 Mar 2022 09:28:20 +0100 Subject: [PATCH] Solution to problem 6 in Python --- src/Year_2016/P6.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Year_2016/P6.py b/src/Year_2016/P6.py index d4c7ea0..e972ac3 100644 --- a/src/Year_2016/P6.py +++ b/src/Year_2016/P6.py @@ -52,5 +52,34 @@ def part_1() -> None: print(f"The message is {message}") +# --- Part Two --- + +# Of course, that would be the message - if you hadn't agreed to use a modified +# repetition code instead. + +# In this modified code, the sender instead transmits what looks like random +# data, but for each character, the character they actually want to send is +# slightly less likely than the others. Even after signal-jamming noise, you +# can look at the letter distributions in each column and choose the least +# common letter to reconstruct the original message. + +# In the above example, the least common character in the first column is a; +# in the second, d, and so on. Repeating this process for the remaining +# characters produces the original message, advent. + +# Given the recording in your puzzle input and this new decoding methodology, +# what is the original message that Santa is trying to send? + + +def part_2() -> None: + _message = [] + for column in signals_transp: + _message.append(Counter(column).most_common()[-1]) + + message = "".join((char[0][0]) for char in _message) + print(f"The message is {message}") + + if __name__ == "__main__": part_1() + part_2()