Python Forum
IndexError in Project Euler attempt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexError in Project Euler attempt
#3
What a fun programming challenge. It is fun just coming up with a solution, but there are many different optimizations that can be tried adding additional challenge. I went from trying 810,000 combinations to 52,115 combinations to 6207 combinations to find the solution.

I think you should restart from scratch and the first thing you solve is to write a test that determines if a number is a palindrome. I wrote mine as a function. That way I could easily try different algorithms and measure how it affected execution time.

Once you get the palindrome test working you need to design an algorithm that tests all possible solutions and reports which combination of numbers produced the highest value palindrome. I am using a for loop. I know the range of three digit numbers so it is easy to specify the range of numbers over which I want to iterate. I don't think it makes much sense converting a number to a string just to count the number of digits. After I got a brute force solution that tests 810,000 combinations of numbers I found some optimizations that eventually reduced that to 6207. The big performance leaps came from analyzing the problem and reducing the range of number I needed to test.
Reply


Messages In This Thread
RE: IndexError in Project Euler attempt - by deanhystad - Aug-06-2020, 10:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculate the Euler Number with more decimal places Pedroski55 10 4,717 Oct-31-2021, 04:45 AM
Last Post: Pedroski55
  Simple while loop only works on first attempt jsb83 2 2,100 Jun-20-2019, 08:57 PM
Last Post: jsb83
  3rd problem from project Euler Richard_SS 6 3,318 Jun-05-2019, 02:06 PM
Last Post: DeaD_EyE
  graphing euler method rondo 1 2,557 May-03-2019, 01:03 AM
Last Post: scidam
  Failed attempt to install pyserial skeeve 4 7,399 Nov-07-2017, 05:08 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020