Advertisement
simeonshopov

Treasure Finder

Feb 14th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import itertools as it
  2. keys = [int(x) for x in input().split()]
  3.  
  4.  
  5. def extract_treasure(a: str, x: str):
  6.     _result = ''
  7.     idx = a.index(x) + 1
  8.     while True:
  9.         if a[idx] == '&':
  10.             break
  11.         _result += a[idx]
  12.         idx += 1
  13.     return _result
  14.  
  15.  
  16. def extract_location(a: str, x: str):
  17.     result_ = ''
  18.     idx = a.index(x) + 1
  19.     while a[idx] != '>':
  20.         result_ += a[idx]
  21.         idx += 1
  22.     return result_
  23.  
  24.  
  25. while True:
  26.     text = input()
  27.     if text == 'find':
  28.         break
  29.     new_text = ''
  30.     for x, y in zip(text, it.cycle(keys)):
  31.         new_chr = chr(ord(x) - y)
  32.         new_text += new_chr
  33.     i= 0
  34.     treasure = ''
  35.     location = ''
  36.     while i < len(new_text):
  37.         if new_text[i] == '&':
  38.             treasure = extract_treasure(new_text, new_text[i])
  39.             i += len(treasure) + 1
  40.         elif new_text[i] == '<':
  41.             location = extract_location(new_text, new_text[i])
  42.             i += len(location)
  43.         i += 1
  44.     print(f'Found {treasure} at {location}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement