I was doing Problem 8 on Project Euler when I ran into a problem. I couldn't find a way to assign each digit in the thousand digit number its own value. Here is my code:
def Problem8():
x = []
num = [73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937765727333001053367881220235421809751254540594752243525849077116705560136048395864467063244157221553975369781797784617406495514929086256932197846862248283972241375657056057490261407972968652414535100474821663704844031998900088952434506585412275886668811642717147992444292823086346567481391912316282458178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450]
def ans(i):
one = num[i]
two = num[i+1]
three = num[i+2]
four = num[i+3]
return one*two*three*four
for i in range(1,(len(num2)-3)):
x.append(ans(i))
print(x)
Problem8()
I was just checking if it would work for the four adjacent digits, not thirteen like the question said. But my array kept on coming up empty. Why is it doing that? Is there a better way?