Created
June 16, 2015 17:06
-
-
Save mukulrawat1986/285bdb644c36d196d885 to your computer and use it in GitHub Desktop.
Project Euler 22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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