I have been trying to solve Problem #3 in ProjectEuler in python. I have tried using recursion to get factors of my factors. But I keep on running into a recursive limit reached error for some reason. Can anyone help me out as to why its happening?
def getPrimeFactors(y):
AllFactors = [[x, int(y/x)] for x in range(1, (int(math.sqrt(y)+1))) if y%x==0]
Flattened_AF = [j for i in AllFactors for j in i]
print(AllFactors)
print(Flattened_AF)
if len(Flattened_AF)==2:
print(Flattened_AF)
return Flattened_AF
else:
PrimeFactors = [x for x in Flattened_AF if len(getPrimeFactors(x))==2]
print (f'loop in else - {PrimeFactors}')
print(max(PrimeFactors)
getPrimeFactors(4)
This is the problem as quoted in the website.
I am sorry if the code readability quality is a bit low but I had been trying to debug for a long time in vain.