Advertisement
go6odn28

03. Treasure Finder

Mar 16th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. class TreasureFinder:
  5.     def __init__(self, key_numbers):
  6.         self.key_numbers = key_numbers
  7.         self.info_about_treasure = []
  8.  
  9.     def find_treasure(self):
  10.         while True:
  11.             decrypted_text = ''
  12.             command = input()
  13.             if command == "find":
  14.                 break
  15.  
  16.             text = command
  17.             for i in range(len(text)):
  18.                 key = self.key_numbers[i % len(self.key_numbers)]
  19.                 char = text[i]
  20.                 ascii_number = ord(char)
  21.                 decrypted_char = chr(ascii_number - key)
  22.                 decrypted_text += decrypted_char
  23.  
  24.             current_type = self._find_message(decrypted_text)
  25.             coordinates = self._find_coordinates(decrypted_text)
  26.  
  27.             self.info_about_treasure.append(f"Found {current_type} at {coordinates}\n")
  28.  
  29.         return ''.join(self.info_about_treasure)
  30.  
  31.     #### Helper methods
  32.     def _find_message(self, decrypted_text_):
  33.         matches = re.findall(r"[&](\w+)[&]", decrypted_text_)
  34.         return matches[0] if matches else None
  35.  
  36.     def _find_coordinates(self, decrypted_text_):
  37.         matches = re.findall(r"[<](\w+)[>]", decrypted_text_)
  38.         return matches[0] if matches else None
  39.  
  40.  
  41. numbers_with_key = [int(x) for x in input().split()]
  42. treasure_finder = TreasureFinder(numbers_with_key)
  43. print(treasure_finder.find_treasure())
  44.  
  45.  
  46.  
  47. # import re
  48. #
  49. #
  50. # def find_message(decrypted_text_):
  51. #     matches = re.findall(r"[&](\w+)[&]", decrypted_text_)
  52. #     return matches[0] if matches else None
  53. #
  54. #
  55. # def find_coordinates(decrypted_text_):
  56. #     matches = re.findall(r"[<](\w+)[>]", decrypted_text_)
  57. #     return matches[0] if matches else None
  58. #
  59. #
  60. # def find_treasure(key_numbers_):
  61. #     result = []
  62. #     while True:
  63. #         decrypted_text = ''
  64. #         command = input()
  65. #         if command == "find":
  66. #             break
  67. #
  68. #         text = command
  69. #         for i in range(len(text)):
  70. #             key = key_numbers_[i % len(key_numbers_)]
  71. #             char = text[i]
  72. #             ascii_number = ord(char)
  73. #             decrypted_char = chr(ascii_number - key)
  74. #             decrypted_text += decrypted_char
  75. #
  76. #         current_type = find_message(decrypted_text)
  77. #         coordinates = find_coordinates(decrypted_text)
  78. #
  79. #         result.append(f"Found {current_type} at {coordinates}\n")
  80. #
  81. #     return ''.join(result)
  82. #
  83. #
  84. # key_numbers = [int(x) for x in input().split()]
  85. # treasure_found = find_treasure(key_numbers)
  86. # print(treasure_found)
  87.  
  88.  
  89.  
  90.  
  91. # import re
  92. #
  93. #
  94. # def find_message(decrypted_text_):
  95. #     matches = re.findall(r"[&](\w+)[&]", decrypted_text_)
  96. #     return matches[0] if matches else None
  97. #
  98. #
  99. # def find_coordinates(decrypted_text_):
  100. #     matches = re.findall(r"[<](\w+)[>]", decrypted_text_)
  101. #     return matches[0] if matches else None
  102. #
  103. #
  104. # key_numbers = [int(x) for x in input().split()]
  105. #
  106. #
  107. # while True:
  108. #     decrypted_text = ''
  109. #     command = input()
  110. #     if command == "find":
  111. #         break
  112. #
  113. #     text = command
  114. #     for i in range(len(text)):
  115. #         key = key_numbers[i % len(key_numbers)]
  116. #         char = text[i]
  117. #         ascii_number = ord(char)
  118. #         decrypted_char = chr(ascii_number - key)
  119. #         decrypted_text += decrypted_char
  120. #
  121. #     current_type = find_message(decrypted_text)
  122. #     coordinates = find_coordinates(decrypted_text)
  123. #
  124. #     print(f"Found {current_type} at {coordinates}")
  125.  
  126.  
  127.  
  128. ######################################################################################
  129. # keys_sequence = list(map(int, input().split()))
  130. # string_sequence = input()
  131. # result = []
  132. #
  133. # while string_sequence != 'find':
  134. #     key_index = 0
  135. #     for char in string_sequence:
  136. #         key = keys_sequence[key_index]
  137. #         result.append(chr(ord(char) - key))
  138. #         key_index = (key_index + 1) % len(keys_sequence)
  139. #     decoded_string = ''.join(result)
  140. #
  141. #     for i in range(1):
  142. #         start_index_type = decoded_string.index('&') + 1
  143. #         end_index_type = decoded_string.index('&', start_index_type)
  144. #         type = decoded_string[start_index_type:end_index_type]
  145. #         start_index_coordinates = decoded_string.index('<') + 1
  146. #         end_index_coordinates = decoded_string.index('>')
  147. #         coordinates = decoded_string[start_index_coordinates:end_index_coordinates]
  148. #         print(f"Found {type} at {coordinates}")
  149. #         result.clear()
  150. #
  151. #     string_sequence = input()
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement