Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if __name__ == "__main__":
- while True:
- information = input()
- n = len(information)
- # First off, try to match the name symbols.
- first_symbol = information[0]
- matched_symbol_index = None
- for i in range(1, n):
- if information[i] == first_symbol:
- matched_symbol_index = i
- break
- if matched_symbol_index is None:
- print("Nothing found!")
- continue
- # Check if all characters between the name symbols are valid.
- name = information[1:matched_symbol_index]
- if not all([ch.isalpha() for ch in name]):
- print("Nothing found!")
- continue
- # Try to match the geohash length next.
- # It should be DIRECTLY after the end symbol of the name.
- geohash_length_symbol_index = matched_symbol_index + 1
- if information[geohash_length_symbol_index] != '=':
- print("Nothing found!")
- continue
- # The geohash length itself has to span until the symbols '!'.
- matched_exclamation_symbol_index = None
- for i in range(geohash_length_symbol_index, n):
- if information[i] == '!':
- matched_exclamation_symbol_index = i
- break
- # Was there such a symbol?
- if matched_exclamation_symbol_index is None:
- print("Nothing found!")
- continue
- geohash_length = information[
- geohash_length_symbol_index+1:matched_exclamation_symbol_index
- ]
- # Make sure the length is a numeric value.
- try:
- geohash_length = int(geohash_length)
- except ValueError:
- print("Nothing found!")
- continue
- # Now search for the geohash code itself.
- # NOTE: There should be another exclamation point after the first one.
- if information[matched_exclamation_symbol_index+1] != '!':
- print("Nothing found!")
- continue
- geohash_code = information[matched_exclamation_symbol_index+2:]
- # Check if the length is valid.
- if len(geohash_code) != geohash_length:
- print("Nothing found!")
- continue
- # If it is, decrypt the message and print output.
- decrypted_code = ""
- for ch in geohash_code:
- decrypted_code += chr(ord(ch) + geohash_length)
- print("Coordinates found! %s -> %s" % (name, decrypted_code))
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement