Return to Snippet

Revision: 27486
at June 10, 2010 20:00 by chroto


Initial Code
#!/usr/bin/python

# Project Euler - Problem 22

f = open("names.txt",'r')

names = []

names = sorted(f.read().replace('"','').split(','),key=str)
i = 1
sum = 0
ans = 0
for string in names:
    chars = list(string)
    for x in chars:
        if x == 'A':
            t = 1
        elif x == 'B':
            t = 2
        elif x == 'C':
            t = 3
        elif x == 'D':
            t = 4
        elif x == 'E':
            t = 5
        elif x == 'F':
            t = 6
        elif x == 'G':
            t = 7
        elif x == 'H':
            t = 8
        elif x == 'I':
            t = 9
        elif x == 'J':
            t = 10
        elif x == 'K':
            t = 11
        elif x == 'L':
            t = 12
        elif x == 'M':
            t = 13
        elif x == 'N':
            t = 14
        elif x == 'O':
            t = 15
        elif x == 'P':
            t = 16
        elif x == 'Q':
            t = 17
        elif x == 'R':
            t = 18
        elif x == 'S':
            t = 19
        elif x == 'T':
            t = 20
        elif x == 'U':
            t = 21
        elif x == 'V':
            t = 22
        elif x == 'W':
            t = 23
        elif x == 'X':
            t = 24
        elif x == 'Y':
            t = 25
        else:
            t = 26
        sum += t
    ans += sum * i
    i += 1
    sum = 0
   
print ans

Initial URL

                                

Initial Description

                                

Initial Title
Project Euler - Problem 22

Initial Tags

                                

Initial Language
Python