Project Euler, fun with math and code
I just discovered the
Project Euler. It is
a series of
challenging mathematical/computer programming problems. I love it! The first
problems are not very challenging but starting at problem 10, I had to scratch
my head to get things done.
To give you an idea, here is the fourth problem:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
Of course you can brut-force and test every single possibility. But there are more stubble ways of finding the solution. Some optimisations can be pretty tricky and it is a lot of fun to optimise math algorithms.
You can also optimise the implementation. In the previous example, lots of people are converting their result to a string and use the string to check if it is a palindrome. Personally I kept it as an integer, and the result was faster!
If you are bored, and would like a quick and fun challenge, try this. Hours and hours of fun!