Skip to content

Instantly share code, notes, and snippets.

@buzibu
Created October 7, 2016 12:55
Show Gist options
  • Save buzibu/4a42b6d752861ab3c8271bc89306e725 to your computer and use it in GitHub Desktop.
Save buzibu/4a42b6d752861ab3c8271bc89306e725 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 7 13:55:20 2016
@author: Vladislav.Zaimov
"""
input_string = input("Input: ").lower()
encoding_scan = {k: 0 for k in r'''abcdefghijklmnopqrstuvwxyz!"#$%&\'()*+,-./:;<=>?@[\\]^_{|}~'''} #init encoding scan
for ch in input_string: #populate encoding scan
encoding_scan[ch] += 1
sorted_scan = sorted(encoding_scan, key=encoding_scan.get, reverse=True) # sort scanned dictionary
encoding_table = {j: 9 - sorted_scan.index(j) for j in sorted_scan[:10]} # populate encoding table
decoded_string = ''.join([str(encoding_table[s]) if s in encoding_table else '+' for s in input_string]) #decode string and replace other characters with +
#print(decoded_string)
numbers_list = decoded_string.split('+')
#print(numbers_list)
sum_of_numbers = 0
for num in numbers_list:
if num != '' :
sum_of_numbers += int(num)
print(sum_of_numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment