I tried to bruteforce euler problem 14 with python without much success.
I used the itertools module but it was too slow. Then I found the formula to solve the problem.
Is there a way to solve the problem using bruteforce?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could store the intermediate value in a dictionary and do a kind of a dynamic programming.
Another approach may be to store every number you encounter and always check whether the number you are currently on is in the map. But I guess this may take a bit longer with so many dictionary look-ups:
You may want to do some testing to find out which one is better, but my bet would be on the first one.