Untitled
unknown
plain_text
2 years ago
887 B
6
Indexable
def decode(message_file):
# Read the contents of the file
with open(message_file, 'r') as file:
lines = file.readlines()
# Extract numbers from each line and create a list
numbers = [int(line.split()[0]) for line in lines]
# Create a pyramid of numbers
pyramid = []
current_number = 1
for i in range(len(numbers)):
pyramid.append(numbers[current_number - 1:current_number])
current_number += 1
# Extract words corresponding to the numbers at the end of each line
message_words = [lines[i - 1].split()[1] for i in pyramid[-1]]
# Join the words to form the decoded message
decoded_message = ' '.join(message_words)
return decoded_message
# Example usage
message_file = 'example.txt' # Replace with the actual file path
decoded_message = decode(message_file)
print(decoded_message)Editor is loading...
Leave a Comment