Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. if __name__ == "__main__":
  2.     while True:
  3.         information = input()
  4.         n = len(information)
  5.  
  6.         # First off, try to match the name symbols.
  7.         first_symbol = information[0]
  8.         matched_symbol_index = None
  9.         for i in range(1, n):
  10.             if information[i] == first_symbol:
  11.                 matched_symbol_index = i
  12.                 break
  13.  
  14.         if matched_symbol_index is None:
  15.             print("Nothing found!")
  16.             continue
  17.  
  18.         # Check if all characters between the name symbols are valid.
  19.         name = information[1:matched_symbol_index]
  20.         if not all([ch.isalpha() for ch in name]):
  21.             print("Nothing found!")
  22.             continue
  23.  
  24.         # Try to match the geohash length next.
  25.         # It should be DIRECTLY after the end symbol of the name.
  26.         geohash_length_symbol_index = matched_symbol_index + 1
  27.         if information[geohash_length_symbol_index] != '=':
  28.             print("Nothing found!")
  29.             continue
  30.  
  31.         # The geohash length itself has to span until the symbols '!'.
  32.         matched_exclamation_symbol_index = None
  33.         for i in range(geohash_length_symbol_index, n):
  34.             if information[i] == '!':
  35.                 matched_exclamation_symbol_index = i
  36.                 break
  37.  
  38.         # Was there such a symbol?
  39.         if matched_exclamation_symbol_index is None:
  40.             print("Nothing found!")
  41.             continue
  42.    
  43.         geohash_length = information[
  44.             geohash_length_symbol_index+1:matched_exclamation_symbol_index
  45.         ]
  46.         # Make sure the length is a numeric value.
  47.         try:
  48.             geohash_length = int(geohash_length)
  49.         except ValueError:
  50.             print("Nothing found!")
  51.             continue
  52.  
  53.         # Now search for the geohash code itself.
  54.         # NOTE: There should be another exclamation point after the first one.
  55.         if information[matched_exclamation_symbol_index+1] != '!':
  56.             print("Nothing found!")
  57.             continue
  58.         geohash_code = information[matched_exclamation_symbol_index+2:]
  59.  
  60.         # Check if the length is valid.
  61.         if len(geohash_code) != geohash_length:
  62.             print("Nothing found!")
  63.             continue
  64.  
  65.         # If it is, decrypt the message and print output.
  66.         decrypted_code = ""
  67.         for ch in geohash_code:
  68.             decrypted_code += chr(ord(ch) + geohash_length)
  69.  
  70.         print("Coordinates found! %s -> %s" % (name, decrypted_code))
  71.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement