20 de julio de 2012

Project Euler 17


#!/usr/bin/env python
oneto9=len(("onetwot"
            "hreefour"
            "fivesixs"
            "eveneigh"
            "tnine"))
tento19=len(("tenelev"
            "entwelv"
            "ethirte"
            "enfourt"
            "eenfift"
            "eensixt"
            "eenseve"
            "nteenei"
            "ghteenn"
            "ineteen"))
oneto99=10*len(("twen"
                "tythirtyf"
                "ortyfifty"
                "sixtyseve"
                "ntyeighty"
                "ninety"))
oneto99+=tento19+oneto9*9
h=len("hundredand")
#x01..x99  #hundreds   #1000
oneto1000=10*oneto99
#100s.1,2,...,9 h don't have 'and'
oneto1000+=(100*(oneto9+h*9)-9*3)
#1000
oneto1000+=len("onethousand")
print oneto1000
I put the strings like that because 
they looked ugly on the blog otherwise.

Puse los strings así porque se veían
feos en el blog.