-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
34 lines (26 loc) · 908 Bytes
/
test.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
def decode(message_file):
decoded_message = []
with open(message_file, 'r') as file:
lines = file.readlines()
pyramid_words = [line.strip().split()[1] for line in lines]
pyramid_ids = [int(line.strip().split()[0]) for line in lines]
print(max(pyramid_ids))
end_idx = 0
length = len(pyramid_ids)
result = []
cnt = 2
pyramids_confirm_flag = False
while end_idx < length:
index = pyramid_ids.index(end_idx + 1)
result.append(pyramid_words[index])
end_idx = end_idx +cnt
cnt = cnt + 1
if end_idx == length - 1:
pyramids_confirm_flag = True
if pyramids_confirm_flag:
return ' '.join(result)
else:
return 'not pyramids satisfied'
# Example usage
decoded_message = decode("coding_qual_input.txt")
print(decoded_message)