- #1
- 2,168
- 192
Homework Statement
https://projecteuler.net/problem=17
Homework Equations
The Attempt at a Solution
Can someone point out where am I doing wrong ? I get some extra numbers but I didnt understand why
Python:
#!/usr/bin/python
A=["one","two","three","four","five","six","seven","eight","nine"]
B=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
C=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
D=["hundred","thousand","and"]
K=[]
for i in range(len(A)):
y=len(A[i])
K.append(y)
for i in range(len(B)):
y=len(B[i])
K.append(y)
L=[]
for i in range(8):
for j in range(9):
l=len(C[i]+A[j])
L.append(l)
for i in range(len(C)):
y=len(C[i])
L.append(y)
K.extend(L)
l=sum(K)
for i in range(len(A)):
p=len(D[0]+D[2]+A[i])*len(K)+l
K.append(p)
for i in range(len(A)):
y=len(D[0]+A[i])
K.append(y)
K.append(len(A[0]+D[1]))
h=sum(K)
print(h)
I know that its current until K.extend(L) part then in the middle when I am trying to find the numbers 100-999 something goes wrong but I didnt undersstand why.
Thanks
Last edited: