Skip to content

Commit 68eb71f

Browse files
committed
Day 06: Solution of part 1
1 parent 087e5d0 commit 68eb71f

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

06/log.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ dvrsen
2424
enarar
2525
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.
2626

27-
Given the recording in your puzzle input, what is the error-corrected version of the message being sent?
27+
Given the recording in your puzzle input, what is the error-corrected version of the message being sent?
28+
29+
Your puzzle answer was nabgqlcw.
30+
31+
The first half of this puzzle is complete! It provides one gold star: *
32+
33+
--- Part Two ---
34+
35+
Of course, that would be the message - if you hadn't agreed to use a modified repetition code instead.
36+
37+
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.
38+
39+
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.
40+
41+
Given the recording in your puzzle input and this new decoding methodology, what is the original message that Santa is trying to send?

06/solution.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
from lib import solution
2+
from lib.dict import Dict
23

34

45
class Solution(solution.Solution):
56
def __init__(self, nr):
67
super().__init__(nr)
8+
self.length = 1
9+
self.dicts = []
10+
self.message = ""
711

812
def calculate(self, test=False):
913
self.read_instructions()
14+
self.init_dicts()
15+
self.calc_message()
1016

1117
def read_instructions(self):
1218
self.read_input(True)
19+
if len(self.input):
20+
self.length = len(self.input[0])
21+
22+
def init_dicts(self):
23+
for i in range(0, self.length):
24+
self.dicts.append(i)
25+
self.dicts[i] = Dict()
26+
27+
def calc_message(self):
28+
for line in self.input:
29+
i = 0
30+
for char in line:
31+
if i < self.length:
32+
self.dicts[i].add(char)
33+
i += 1
34+
for i in range(0, self.length):
35+
self.message += self.dicts[i].get_sorted_string_by_value_and_key(1)
36+
self.set_solution(1, self.message)

06/test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ def setUpClass(cls):
77
cls.nr = '06'
88

99
def test_1(self):
10-
test_input = """
11-
eedadn
10+
test_input = """eedadn
1211
drvtee
1312
eandsr
1413
raavrd
@@ -23,7 +22,6 @@ def test_1(self):
2322
vntsnd
2423
vrdear
2524
dvrsen
26-
enarar
27-
"""
25+
enarar"""
2826
self.execute_test(test_input)
2927
self.assertEqual("easter", self.solution.get_solution(1))

0 commit comments

Comments
 (0)