-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuningTrouble.py
74 lines (59 loc) · 1.78 KB
/
TuningTrouble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
"""TuningTrouble.py
Author: Bissallah Ekele - bAe
Date: 08/12/2022
Description: Fix Faulty Communication System.
"""
# Add a subroutine -
# Lock on to another elve's signal to communicate
#
# Start of packet marker in datastream
# 1st position - four different characters
#
# Pseudocode:
# place fours in a set - watch memory use
# if set size is four - return index at upper bound
def get_marker(datastream, window):
"""Get start-of marker
Keyword argument:
datastream -- elve's position datastream string
window -- int sliding window to consider
Return:
start-of marker int
"""
packet_match = set()
for lower_bound in range(len(datastream)):
packet_match.update(datastream[lower_bound:window+lower_bound])
if len(packet_match) == window:
return lower_bound + window
packet_match.clear()
def get_part_1(input_list):
"""Get start-of-packet marker
Keyword argument:
input_list -- elve's position datastream list
Return:
start-of-packet marker int
"""
for datastream in input_list:
print(get_marker(datastream, 4))
def get_part_2(input_list):
"""Get start-of-message marker
Keyword argument:
input_list -- elve's position datastream list
Return:
start-of-message marker int
"""
for datastream in input_list:
print(get_marker(datastream, 14))
def main():
test_input = r"test-input"
puzzle_input = "puzzle-input"
file_name = puzzle_input #test_input
with open(file_name) as f:
input_list = f.read().splitlines()
print("Part_1: ")
get_part_1(input_list)
print("\nPart_2: ")
get_part_2(input_list)
if __name__ == "__main__":
main()