Problem 4


Problem Find the largest palindrome which is the product of two 3-digit numbers. General solution There are 900 three digit numbers (100-999), so to find the product of all the possible combinations we would need 900 * 900 = 810,000 multiplications. This is trivial on a modern processor and therefore we can brute force a solution without needing to optimise, although the question of whether we could reduce the search space beforehand remains open.…
Read more ⟶

Problem 3


Problem Find the largest prime factor of a given number, in this case: 600851475143. A factor of n is a number such that n divided by the factor gives a remainder of zero. A prime factor is a factor which is also a prime number, i.e. it has no factors other than 1 and the number itself. General solution A brute-force solution to this problem would involve dividing n by every number between 2 and n - 1.…
Read more ⟶

Problem 2


Problem Find the sum of the even Fibonacci numbers up to 4 million. General solution Given the small search space, the simplest solution is to calculate the next Fibonacci number and check if it is even, and if so add it to the running total. Although the list of Fibonacci numbers up to 4 million is long, we only need to keep the previous two numbers in memory, as that is sufficient to calculate the next number.…
Read more ⟶

Problem 1


Problem Find the sum of all the numbers evenly divisible by 3 or 5 below 1000. General solution Given the small search space, the simplest solution is to iterate over the numbers from 1 to 999 and add them to a running total if they are evenly divisible by 3 or 5. Solution: Go package main import ( "fmt" ) func main() { var sum int = 0 for num := 1; num < 1000; num++ { if num % 3 == 0 || num % 5 == 0 { sum += num } } fmt.…
Read more ⟶