From 2b40cdd77a247af463d7c4bd210b282aba9dec13 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sat, 5 Mar 2022 09:22:49 +0100 Subject: [PATCH] Solution to problem 6 part 1 in Python --- src/Year_2016/P6.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Year_2016/P6.py diff --git a/src/Year_2016/P6.py b/src/Year_2016/P6.py new file mode 100644 index 0000000..d4c7ea0 --- /dev/null +++ b/src/Year_2016/P6.py @@ -0,0 +1,56 @@ +# --- Day 6: Signals and Noise --- + +# Something is jamming your communications with Santa. Fortunately, your signal +# is only partially jammed, and protocol in situations like this is to switch +# to a simple repetition code to get the message through. + +# In this model, the same message is sent repeatedly. You've recorded the +# repeating message signal (your puzzle input), but the data seems quite +# corrupted - almost too badly to recover. Almost. + +# All you need to do is figure out which character is most frequent for each +# position. For example, suppose you had recorded the following messages: + +# eedadn +# drvtee +# eandsr +# raavrd +# atevrs +# tsrnev +# sdttsa +# rasrtv +# nssdts +# ntnada +# svetve +# tesnvt +# vntsnd +# vrdear +# dvrsen +# enarar + +# The most common character in the first column is e; in the second, a; in the +# third, s, and so on. Combining these characters returns the error-corrected +# message, easter. + +# Given the recording in your puzzle input, what is the error-corrected version +# of the message being sent? + +from collections import Counter + +with open("files/P6.txt") as f: + signals = [line for line in f.read().strip().split()] + +signals_transp = list(zip(*signals)) + + +def part_1() -> 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()