Solution to problem 6 part 1 in Python
This commit is contained in:
parent
caa8022dda
commit
2b40cdd77a
56
src/Year_2016/P6.py
Normal file
56
src/Year_2016/P6.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user