Skip to content

Instantly share code, notes, and snippets.

@mukulrawat1986
Created June 16, 2015 17:06
Show Gist options
  • Save mukulrawat1986/285bdb644c36d196d885 to your computer and use it in GitHub Desktop.
Save mukulrawat1986/285bdb644c36d196d885 to your computer and use it in GitHub Desktop.
Project Euler 22
# function to get the alphabetical value
def value(char):
return ord(char) - 64
# open file and sort the strings
file = open('names.txt','r')
names = file.read().split(',')
names = sorted(names)
total = 0
for name in names:
val = 0
for char in name:
if ord(char) >= 65: # excludes the " characters
val += value(char)
total += (val * (names.index(name) + 1))
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment