First of all - it is fun. Some 20 years back I used to participate in programming competitions (i.e. solving algorithmic problems). Since that I'm mostly working in enterprise environment and solving different types of problems. It's always good to shake your memory.
Secondly - it allows me to switch focus from my day-to-day work and refresh my former knowledge.
Thirdly - it forces me to discover new things for me, new algorithms, new approaches, etc.
And last, but not least - I do enjoy cracking these quite challenging problems.
- Programming language is not important, I chose golang but I could have achieved the same results with any other language.
- First 50 or so problems can be solved without knowing anything about algorithms - mostly brute-force solutions are viable. I think I wrote solutions for them during two or maybe three evenings.
- The bigger the problem number, the more complex they are. I.e. 5% problem from first hundred problems is much easier than 5% problem from 7-th hundred.
- Getting to top 1% (at the time of writing it is equivalent of solving 111 or more problems) is not that hard. It took me about 2 weeks to reach this milestone (mosly solving problems in the evenings)
- Useful tools to use:
- https://www.alpertron.com.ar/QUAD.HTM - generic quadratic Diophantine equation solver - will be used in a number of problems
- https://www.wolframalpha.com/ - Wolfram Alpha is a great tool to quickly investigate some functions and expressions, this might not give you solution but can help to verify your assumptions
- Nice techniques to master (they are used in many problems):
- Dynamic programming - https://en.wikipedia.org/wiki/Dynamic_programming
- Prime numbers - https://en.wikipedia.org/wiki/Prime_number
- Euler's totient function - https://en.wikipedia.org/wiki/Euler%27s_totient_function
- Fibonacci numbers - https://en.wikipedia.org/wiki/Fibonacci_number
- Greatest common divisor - https://en.wikipedia.org/wiki/Greatest_common_divisor
- Pythagorean Triple - https://en.wikipedia.org/wiki/Pythagorean_triple
- Don't look for other people solutions (as it turned out you can quite easily find the solution for almost all problems) - try to solve it myself first. It will be more fun than just copying the result from the others.
- Try to figure out algorithm complexity beforehand. Efficient algorithm for Project Euler problem should check at most 50'000'000 possibilities (to fit into recommended time limit of 1 minute). For example if I see that need to find sum of numbers below 10^7 - it gives a clue that every number should be checked in constant time (i.e. O(1)).
- One cannot know all algorithms - it's OK to google algorithms and ideas of solutions.
- Solution that runs over 10 seconds on a modern hardware is most likely sub-optimal. Project Euler states that the reasonable limit for the program to find a solution is one minute, but I think only a couple of my solutions run slower than 15 seconds. If I see that I go over this limit I spend some time figuring out what can be improved.
- After I solved the problem I try to google solutions of other people to verify my ideas and learn something from others.
- Project Euler opens you an internal discussion thread for a problem once you solve it - it's good to check other people ideas there.
Here are my solved problems. For all of them source code is available plus some very brief explanation of my solution. Mostly breakdown does not explain each and every aspect of the solution - my goal is to provide you a hint how to address the problem.
- #1 - Multiples of 3 or 5
- #2 - Even Fibonacci numbers
- #3 - Largest prime factor
- #4 - Largest palindrome product
- #5 - Smallest multiple
- #6 - Sum square difference
- #7 - 10001st prime
- #8 - Largest product in a series
- #9 - Special Pythagorean triplet
- #10 - Summation of primes
- #11 - Largest product in a grid
- #12 - Highly divisible triangular number
- #13 - Large sum
- #14 - Longest Collatz sequence
- #15 - Lattice paths
- #16 - Power digit sum
- #17 - Number letter counts
- #18 - Maximum path sum I
- #19 - Counting Sundays
- #20 - Factorial digit sum
- #21 - Amicable numbers
- #22 - Names scores
- #23 - Non-abundant sums - no description
- #24 - Lexicographic permutations
- #25 - 1000-digit Fibonacci number
- #26 - Reciprocal cycles
- #27 - Quadratic primes
- #28 - Number spiral diagonals
- #29 - Distinct powers
- #30 - Digit fifth powers
- #31 - Coin sums
- #32 - Pandigital products - no description
- #33 - Digit cancelling fractions - no description
- #34 - Digit factorials - no description
- #35 - Circular primes - no description
- #36 - Double-base palindromes - no description
- #37 - Truncatable primes - no description
- #38 - Pandigital multiples - no description
- #39 - Integer right triangles - no description
- #40 - Champernowne's constant - no description
- #41 - Pandigital prime - no description
- #42 - Coded triangle numbers - no description
- #43 - Sub-string divisibility - no description
- #44 - Pentagon numbers - no description
- #45 - Triangular, pentagonal, and hexagonal - no description
- #46 - Goldbach's other conjecture - no description
- #47 - Distinct primes factors - no description
- #48 - Self powers - no description
- #49 - Prime permutations - no description
- #50 - Consecutive prime sum - no description
- #51 - Prime digit replacements - no description
- #52 - Permuted multiples - no description
- #53 - Combinatoric selections - no description
- #54 - Poker hands - no description
- #55 - Lychrel numbers - no description
- #56 - Powerful digit sum - no description
- #57 - Square root convergents - no description
- #58 - Spiral primes - no description
- #59 - XOR decryption - no description
- #60 - Prime pair sets - no description
- #61 - Cyclical figurate numbers - no description
- #62 - Cubic permutations - no description
- #63 - Powerful digit counts - no description
- #64 - Odd period square roots - no description
- #65 - Convergents of e - no description
- #66 - Diophantine equation - no description
- #67 - Maximum path sum II - no description
- #68 - Magic 5-gon ring - no description
- #69 - Totient maximum - no description
- #70 - Totient permutation - no description
- #71 - Ordered fractions - no description
- #72 - Counting fractions - no description
- #73 - Counting fractions in a range - no description
- #74 - Digit factorial chains - no description
- #75 - Singular integer right triangles - no description
- #76 - Counting summations - no description
- #77 - Prime summations - no description
- #78 - Coin partitions
- #79 - Passcode derivation - no description
- #80 - Square root digital expansion - no description
- #81 - Path sum: two ways - no description
- #82 - Path sum: three ways - no description
- #83 - Path sum: four ways - no description
- #84 - Monopoly odds
- #85 - Counting rectangles - no description
- #86 - Cuboid route - no description
- #87 - Prime power triples - no description
- #88 - Product-sum numbers
- #89 - Roman numerals - no description
- #90 - Cube digit pairs - no description
- #91 - Right triangles with integer coordinates - no description
- #92 - Square digit chains - no description
- #93 - Arithmetic expressions - no description
- #94 - Almost equilateral triangles - no description
- #95 - Amicable chains - no description
- #96 - Su Doku - no description
- #97 - Large non-Mersenne prime - no description
- #98 - Anagramic squares - no description
- #99 - Largest exponential - no description
- #100 - Arranged probability - no description
- #101 - Optimum polynomial - no description
- #102 - Triangle containment - no description
- #103 - Special subset sums: optimum - no description
- #104 - Pandigital Fibonacci ends - no description
- #105 - Special subset sums: testing - no description
- #107 - Minimal network - no description
- #108 - Diophantine reciprocals I - no description
- #109 - Darts - no description
- #110 - Diophantine reciprocals II
- #111 - Primes with runs
- #112 - Bouncy numbers - no description
- #113 - Non-bouncy numbers - no description
- #114 - Counting block combinations I - no description
- #116 - Red, green or blue tiles - no description
- #117 - Red, green, and blue tiles - no description
- #118 - Pandigital prime sets - no description
- #119 - Digit power sum - no description
- #120 - Square remainders - no description
- #121 - Disc game prize fund
- #122 - Efficient exponentiation - no description
- #123 - Prime square remainders - no description
- #124 - Ordered radicals - no description
- #125 - Palindromic sums - no description
- #127 - abc-hits
- #129 - Repunit divisibility
- #130 - Composites with prime repunit property
- #131 - Prime cube partnership
- #132 - Large repunit factors
- #133 - Repunit nonfactors
- #134 - Prime pair connection - no description
- #135 - Same differences - no description
- #136 - Singleton difference - no description
- #137 - Fibonacci golden nuggets
- #138 - Special isosceles triangles - no description
- #139 - Pythagorean tiles - no description
- #140 - Modified Fibonacci golden nuggets
- #142 - Perfect Square Collection - no description
- #144 - Investigating multiple reflections of a laser beam
- #145 - How many reversible numbers are there below one-billion? - no description
- #146 - Investigating a Prime Pattern
- #148 - Exploring Pascal's triangle
- #149 - Searching for a maximum-sum subsequence
- #151 - Paper sheets of standard sizes: an expected-value problem - no description
- #155 - Counting Capacitor Circuits
- #158 - Exploring strings for which only one character comes lexicographically after its neighbour to the left
- #159 - Digital root sums of factorisations
- #160 - Factorial trailing digits
- #162 - Hexadecimal numbers - no description
- #164 - Numbers for which no three consecutive digits have a sum greater than a given value - no description
- #165 - Intersections
- #166 - Criss Cross - no description
- #168 - Number Rotations
- #169 - Exploring the number of different ways a number can be expressed as a sum of powers of 2
- #170 - Find the largest 0 to 9 pandigital that can be formed by concatenating products
- #171 - Finding numbers for which the sum of the squares of the digits is a square
- #172 - Investigating numbers with few repeated digits
- #173 - Using up to one million tiles how many different "hollow" square laminae can be formed? - no description
- #174 - Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements
- #178 - Step Numbers
- #179 - Consecutive positive divisors - no description
- #182 - RSA encryption
- #183 - Maximum product of parts - no description
- #187 - Semiprimes - no description
- #188 - The hyperexponentiation of a number
- #190 - Maximising a weighted product - no description
- #191 - Prize Strings - no description
- #195 - Inscribed circles of triangles with one angle of 60 degrees
- #193 - Squarefree Numbers
- #197 - Investigating the behaviour of a recursively defined sequence - no description
- #203 - Squarefree Binomial Coefficients - no description
- #204 - Generalised Hamming Numbers - no description
- #205 - Dice Game - no description
- #206 - Concealed Square - no description
- #207 - Integer partition equations
- #211 - Divisor Square Sum
- #214 - Totient Chains - no description
- #216 - Investigating the primality of numbers of the form 2n^2-1
- #225 - Tribonacci non-divisors
- #230 - Fibonacci Words
- #231 - The prime factorisation of binomial coefficients - no description
- #234 - Semidivisible numbers
- #235 - An Arithmetic Geometric sequence - no description
- #243 - Resilience
- #249 - Prime Subset Sums
- #250 - 250250
- #259 - Reachable Numbers
- #265 - Binary Circles
- #277 - A Modified Collatz sequence
- #279 - Triangles with integral sides and an integral angle
- #291 - Panaitopol Primes
- #293 - Pseudo-Fortunate Numbers
- #297 - Zeckendorf Representation
- #301 - Nim
- #303 - Multiples with small digits - no description
- #304 - Primonacci
- #315 - Digital root clocks - no description
- #345 - Matrix Sum
- #346 - Strong Repunits
- #347 - Largest integer divisible by two primes - no description
- #348 - Sum of a square and a cube - no description
- #351 - Hexagonal orchards
- #357 - Prime generating integers - no description
- #358 - Cyclic numbers
- #365 - A huge binomial coefficient
- #381 - (prime-k) factorial - no description
- #387 - Harshad Numbers
- #401 - Sum of squares of divisors
- #429 - Sum of squares of unitary divisors
- #479 - Roots on the Rise
- #485 - Maximum number of divisors
- #491 - Double pandigital number divisible by 11 - no description
- #493 - Under The Rainbow
- #500 - Problem 500!!
- #504 - Square on the Inside - no description
- #518 - Prime triples and geometric sequences - no description
- #531 - Chinese leftovers
- #549 - Divisibility of factorials
- #571 - Super Pandigital Numbers
- #587 - Concave triangle - no description
- #601 - Divisibility streaks
- #618 - Numbers with a given prime factor sum
- #650 - Divisors of Binomial Product - no description
- #684 - Inverse Digit Sum
- #686 - Powers of Two - no description
- #692 - Siegbert and Jo
- #700 - Eulercoin
- #719 - Number Splitting - no description
- #725 - Digit sum numbers
- #745 - Sum of Squares II
- #749 - Near Power Sums
- #751 - Concatenation Coincidence - no description
- #757 - Stealthy Numbers