Thoughts on Solving My First 100 Problems on Project Euler
A few years ago I set a goal to solve 100 problems on Project Euler with python. My motivation was to learn as much about problem solving as I could and ultimately finish with Problem 96, a sudoku solver. My plan was to write about my progess in a blog. More than three years later, I finally finished that goal (although I quickly abandoned that blog after starting it). The problems definitely got harder and it took me a while to get motivated to work on them as well as to solve them. I did however come up with three major lessons learned in my first 100 problems:
1 - Narrow the search space By far the biggest lesson I learned was how to cut down on possible options before even starting to program. Since one of the rules of Project Euler is to solve each problem within a minute, brute force quickly gets thrown out the window. An example would be taking the square root of the upper bound to reduce the amount of searching of numbers above the square root. I learned to think more in depth about the problem and try to optimize the search window to be more effiecient.
2 - Have a toolbox and use it I quickly developed a set of functions that I imported frequently that included functions such as a prime number sieve, a function to check if a number was pandigital, and a function for getting all factors of a number. I found that the way the problems were structured meant that I was frequently coming back to issues or approaches I used on earlier problems and I did not want to have to rewrite functions i had previously used.
3 - Google and Stack Overflow are your friends
I used both frequently, there are many other people who post their
answers or even just the
solutions. You can
use these if you want, but I found I was able to learn about libraries such as
itertools, differences between python’s
many different types of search algorithms.
I would highly encourage you to try out a few problems on Project Euler, I had fun and learned way more python than I thought I would (even if it took me a few years longer than originally planned.)