Skip to content

Instantly share code, notes, and snippets.

@jgc128
Last active August 29, 2015 14:08
Show Gist options
  • Save jgc128/5cf29b9112bc29dbdad7 to your computer and use it in GitHub Desktop.
Save jgc128/5cf29b9112bc29dbdad7 to your computer and use it in GitHub Desktop.
timus
#!/usr/bin/python3
from sys import stdin
startChar = ord('a')
endChar = ord('z')
customChars = [['.',',','!'],[' ']]
def createCustomCharsTable():
customCharsTable = {}
for cList in customChars:
for idx, c in enumerate(cList):
customCharsTable[c] = idx + 1
return customCharsTable
def getCost(char):
nc = ord(char)
if nc <= endChar and nc >= startChar:
cost = (nc - startChar) % 3 + 1
else:
cost = customCharsTable[char]
return cost
customCharsTable = createCustomCharsTable()
slogan = stdin.readline()[:-1] # remove \n char at the end of the string
costs = [getCost(char) for char in slogan]
totalCost = sum(costs)
print(totalCost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment