25 de julio de 2012

Project Euler 22

Forcing it functional.
Forzándolo funcional.
#!/usr/bin/env python
#character points
def ordb(c):
    return ord(c)-ord("A")+1
#word points
def wpoints(name):
    return sum(map(ordb,name))
#position
def pos():
    i=1
    while True:
        yield i
        i+=1
#position index
indx=pos()
#word score
def score(name):
    return wpoints(name)*indx.next()
f=open("names.txt","r")
#clean
txt=f.read()[1:-1].split('","')
txt.sort()
print sum(map(score,txt))