Project Euler

Project Euler

Project Euler is a website that lists math/programming problems to be solved for fun, or to help learn a new programming language. I recently started doing some of the problems to aid me in learning Clojure, and decided it would be interesting to compile my solutions. The table below lists all of the problems on Project Euler, and links to the problem description and my solutions. On the right are columns listing the running time for my solutions in each language. The problems are designed to be solvable in less than a minute in program running time, so any of my solutions that run longer than that are marked in red.

#Problem Clojure Erlang Ruby Scala
1 Add all the natural numbers below one thousand that are multiples of 3 or 5. 1.54 0.198 0.01 0.24
2 Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million. 1.61 0.417 0.02 0.21
3 Find the largest prime factor of a composite number. - 0.14 0.03 0.26
4 Find the largest palindrome made from the product of two 3-digit numbers. 6.04 0.52 3.64 1.35
5 What is the smallest number divisible by each of the numbers 1 to 20? - 0.12 0.02 -
6 What is the difference between the sum of the squares and the square of the sums? 1.76 0.14 0.02 0.18
7 Find the 10001<sup>st</sup> prime. - 0.56 0.98 0.51
8 Discover the largest product of five consecutive digits in the 1000-digit number. - 0.12 0.05 0.33
9 Find the only Pythagorean triplet, {<var>a</var>, <var>b</var>, <var>c</var>}, for which <var>a</var> + <var>b</var> + <var>c</var> = 1000. - 0.473 0.338 0.5
10 Calculate the sum of all the primes below two million. - 10.45 28.48 0.86
11 What is the greatest product of four numbers on the same straight line in the 20 by 20 grid? - 0.12 0.0 0.25
12 What is the value of the first triangle number to have over five hundred divisors? - 9.57 4.56 0.52
13 Find the first ten digits of the sum of one-hundred 50-digit numbers. - 0.433 0.02 -
14 Find the longest sequence using a starting number under one million. - 7.133 13.64 -
15 Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner? - 0.11 0.02 -
16 What is the sum of the digits of the number 2<sup>1000</sup>? 1.56 0.12 0.02 0.22
17 How many letters would be needed to write all the numbers in words from 1 to 1000? - 0.203 0.04 -
18 Find the maximum sum travelling from the top of the triangle to the base. - 0.21 0.02 -
19 How many Sundays fell on the first of the month during the twentieth century? - 0.205 0.021 -
20 Find the sum of digits in 100! 1.62 0.12 0.01 0.19
21 Evaluate the sum of all amicable pairs under 10000. - 4.66 3.51 -
22 What is the total of all the name scores in the file of first names? - 0.278 0.12 -
23 Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. - 18.0 9.45 -
24 What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? - 0.08 0.0 -
25 What is the first term in the Fibonacci sequence to contain 1000 digits? 3.58 0.13 0.032 -
26 Find the value of <i>d</i> &lt; 1000 for which 1/<i>d</i> contains the longest recurring cycle. - - - -
27 Find a quadratic formula that produces the maximum number of primes for consecutive values of <i>n</i>. - 4.62 7.23 -
28 What is the sum of both diagonals in a 1001 by 1001 spiral? - 0.204 0.03 -
29 How many distinct terms are in the sequence generated by <i>a<sup>b</sup></i> for 2 &le; <i>a</i> &le; 100 and 2 &le; <i>b</i> &le; 100? 3.37 0.2 0.08 -
30 Find the sum of all the numbers that can be written as the sum of fifth powers of their digits. - 1.56 6.82 -
31 Investigating combinations of English currency denominations. - 7.165 0.372 -
32 Find the sum of all numbers that can be written as pandigital products. - 3.58 0.98 -
33 Discover all the fractions with an unorthodox cancelling method. - - 0.12 -
34 Find the sum of all numbers which are equal to the sum of the factorial of their digits. - - 0.78 -
35 How many circular primes are there below one million? - 9.1 6.46 -
36 Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2. 5.29 0.62 2.06 -
37 Find the sum of all eleven primes that are both truncatable from left to right and right to left. - - 0.1 -
38 What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, ... ? - - 0.221 -
39 If <i>p</i> is the perimeter of a right angle triangle, {<i>a</i>, <i>b</i>, <i>c</i>}, which value, for <i>p</i> ≤ 1000, has the most solutions? - - 0.471 -
40 Finding the <i>n</i><sup>th</sup> digit of the fractional part of the irrational number. - - 0.438 -
41 What is the largest <i>n</i>-digit pandigital prime that exists? - - 1.09 -
42 How many triangle words does the list of common English words contain? - 0.13 0.05 -
43 Find the sum of all pandigital numbers with an unusual sub-string divisibility property. - 0.1 0.02 -
44 Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal. - - 45.97 -
45 After 40755, what is the next triangle number that is also pentagonal and hexagonal? - - 2.05 -
46 What is the smallest odd composite that cannot be written as the sum of a prime and twice a square? - - 0.93 -
47 Find the first four consecutive integers to have four distinct primes factors. - 37.73 19.79 -
48 Find the last ten digits of 1<sup>1</sup> + 2<sup>2</sup> + ... + 1000<sup>1000</sup>. 2.08 0.13 0.0 -
49 Find arithmetic sequences, made of prime terms, whose four digits are permutations of each other. - - 0.0 -
50 Which prime, below one-million, can be written as the sum of the most consecutive primes? - 8.65 0.67 -
51 Find the smallest prime which, by changing the same part of the number, can form eight different primes. - - - -
52 Find the smallest positive integer, <i>x</i>, such that 2<i>x</i>, 3<i>x</i>, 4<i>x</i>, 5<i>x</i>, and 6<i>x</i>, contain the same digits in some order. - 2.79 4.32 -
53 How many values of C(<i>n</i>,<i>r</i>), for 1 ≤ <i>n</i> ≤ 100, exceed one-million? - 0.19 0.25 -
54 How many hands did player one win in the game of poker? - - 0.13 -
55 How many Lychrel numbers are there below ten-thousand? - 0.54 0.2 -
56 Considering natural numbers of the form, <i>a<sup>b</sup></i>, finding the maximum digital sum. 5.47 0.38 2.18 -
57 Investigate the expansion of the continued fraction for the square root of two. - - 3.66 -
58 Investigate the number of primes that lie on the diagonals of the spiral grid. - 9.78 42.71 -
59 Using a brute force attack, can you decrypt the cipher using XOR encryption? - - - -
60 Find a set of five primes for which any two primes concatenate to produce another prime. - - - -
61 Find the sum of the only set of six 4-digit figurate numbers with a cyclic property. - - 1.28 -
62 Find the smallest cube for which exactly five permutations of its digits are cube. - 0.2 0.31 -
63 How many <i>n</i>-digit positive integers exist which are also an <i>n</i><sup>th</sup> power? - - 0.023 -
64 How many continued fractions for <i>N</i> ≤ 10000 have an odd period? - - - -
65 Find the sum of digits in the numerator of the 100<sup>th</sup> convergent of the continued fraction for <i>e</i>. - - 0.04 -
66 Investigate the Diophantine equation <i>x</i><sup>2</sup> &#8722; D<i>y</i><sup>2</sup> = 1. - - - -
67 Using an efficient algorithm find the maximal sum in the triangle? - 0.476 0.061 -
68 What is the maximum 16-digit string for a "magic" 5-gon ring? - - - -
69 Find the value of <i>n</i> &le; 1,000,000 for which <i>n</i>/&phi;(<i>n</i>) is a maximum. - 0.14 - -
70 Investigate values of <var>n</var> for which &#966;(<var>n</var>) is a permutation of <var>n</var>. - - - -
71 Listing reduced proper fractions in ascending order of size. - - 41.44 -
72 How many elements would be contained in the set of reduced proper fractions for <i>d</i> &le; 1,000,000? - 28.71 - -
73 How many fractions lie between 1/3 and 1/2 in a sorted set of reduced proper fractions? - - 47.35 -
74 Determine the number of factorial chains that contain exactly sixty non-repeating terms. - 12.94 - -
75 Find the number of different lengths of wire can that can form a right angle triangle in only one way. - - - -
76 How many different ways can one hundred be written as a sum of at least two positive integers? - - - -
77 What is the first value which can be written as the sum of primes in over five thousand different ways? - - - -
78 Investigating the number of ways in which coins can be separated into piles. - - - -
79 By analysing a user's login attempts, can you determine the secret numeric passcode? - - - -
80 Calculating the digital sum of the decimal digits of irrational square roots. - - 2.4 -
81 Find the minimal path sum from the top left to the bottom right by moving right and down. - - - -
82 Find the minimal path sum from the left column to the right column. - - - -
83 Find the minimal path sum from the top left to the bottom right by moving left, right, up, and down. - - - -
84 In the game, Monopoly, find the three most popular squares when using two 4-sided dice. - - - -
85 Investigating the number of rectangles in a rectangular grid. - - - -
86 Exploring the shortest path from one corner of a cuboid to another. - - - -
87 Investigating numbers that can be expressed as the sum of a prime square, cube, and fourth power? - 4.08 - -
88 Exploring minimal product-sum numbers for sets of different sizes. - - - -
89 Develop a method to express Roman numerals in minimal form. - - - -
90 An unexpected way of using two cubes to make a square. - - - -
91 Find the number of right angle triangles in the quadrant. - 23.664 - -
92 Investigating a square digits number chain with a surprising property. - - 0.76 -
93 Using four distinct digits and the rules of arithmetic, find the longest sequence of target numbers. - - - -
94 Investigating almost equilateral triangles with integral sides and area. - - - -
95 Find the smallest member of the longest amicable chain with no element exceeding one million. - - - -
96 Devise an algorithm for solving Su Doku puzzles. - - 2.49 -
97 Find the last ten digits of the non-Mersenne prime: 28433 &times; 2<sup>7830457</sup> + 1. 1.63 0.241 0.02 -
98 Investigating words, and their anagrams, which can represent square numbers. - - - -
99 Which base/exponent pair in the file has the greatest numerical value? - 0.222 0.035 -
100 Finding the number of blue discs for which there is 50% chance of taking two blue. - - - -
101 Investigate the optimum polynomial function to model the first <i>k</i> terms of a given sequence. - - - -
102 For how many triangles in the text file does the interior contain the origin? - - - -
103 Investigating sets with a special subset sum property. - - - -
104 Finding Fibonacci numbers for which the first and last nine digits are pandigital. - 67.756 - -
105 Find the sum of the special sum sets in the file. - - - -
106 Find the minimum number of comparisons needed to identify special sum sets. - - - -
107 Determining the most efficient way to connect the network. - - - -
108 Solving the Diophantine equation 1/<var>x</var> + 1/<var>y</var> = 1/<var>n</var>. - - - -
109 How many distinct ways can a player checkout in the game of darts with a score of less than 100? - - - -
110 Find an efficient algorithm to analyse the number of solutions of the equation 1/<var>x</var> + 1/<var>y</var> = 1/<var>n</var>. - - - -
111 Search for 10-digit primes containing the maximum number of repeated digits. - - - -
112 Investigating the density of "bouncy" numbers. - 8.078 - -
113 How many numbers below a googol (10<sup>100</sup>) are not &quot;bouncy&quot;? - - - -
114 Investigating the number of ways to fill a row with separated blocks that are at least three units long. - - - -
115 Finding a generalisation for the number of ways to fill a row with separated blocks. - - - -
116 Investigating the number of ways of replacing square tiles with one of three coloured tiles. - - 0.039 -
117 Investigating the number of ways of tiling a row using different-sized tiles. - - 0.031 -
118 Exploring the number of ways in which sets containing prime elements can be made. - - - -
119 Investigating the numbers which are equal to sum of their digits raised to some power. - - - -
120 Finding the maximum remainder when (<i>a</i> &minus; 1)<sup><i>n</i></sup> + (<i>a</i> + 1)<sup><i>n</i></sup> is divided by <i>a</i><sup>2</sup>. - - - -
121 Investigate the game of chance involving coloured discs. - - - -
122 Finding the most efficient exponentiation method. - - - -
123 Determining the remainder when (<i>p<sub>n</sub></i> &minus; 1)<sup><i>n</i></sup> + (<i>p<sub>n</sub></i> + 1)<sup><i>n</i></sup> is divided by <i>p<sub>n</sub></i><sup>2</sup>. - - - -
124 Determining the <i>k</i><sup>th</sup> element of the sorted radical function. - - 15.94 -
125 Finding square sums that are palindromic. - - 1.24 -
126 Exploring the number of cubes required to cover every visible face on a cuboid. - - - -
127 Investigating the number of <i>abc-hits</i> below a given limit. - - - -
128 Which tiles in the hexagonal arrangement have prime differences with neighbours? - - - -
129 Investigating minimal repunits that divide by <i>n</i>. - - - -
130 Finding composite values, <i>n</i>, for which <i>n</i>&minus;1 is divisible by the length of the smallest repunits that divide it. - - - -
131 Determining primes, <i>p</i>, for which <i>n</i><sup>3</sup> + <i>n</i><sup>2</sup><i>p</i> is a perfect cube. - - - -
132 Determining the first forty prime factors of a very large repunit. - - - -
133 Investigating which primes will never divide a repunit containing 10<sup><i>n</i></sup> digits. - - - -
134 Finding the smallest positive integer related to any pair of consecutive primes. - - - -
135 Determining the number of solutions of the equation <i>x</i><sup>2</sup> &minus; <i>y</i><sup>2</sup> &minus; <i>z</i><sup>2</sup> = <i>n</i>. - - - -
136 Discover when the equation <i>x</i><sup>2</sup> &minus; <i>y</i><sup>2</sup> &minus; <i>z</i><sup>2</sup> = <i>n</i> has a unique solution. - - - -
137 Determining the value of infinite polynomial series for which the coefficients are Fibonacci numbers. - - - -
138 Investigating isosceles triangle for which the height and base length differ by one. - - - -
139 Finding Pythagorean triangles which allow the square on the hypotenuse square to be tiled. - - - -
140 Investigating the value of infinite polynomial series for which the coefficients are a linear second order recurrence relation. - - - -
141 Investigating progressive numbers, <i>n</i>, which are also square. - - - -
142 Perfect Square Collection - - - -
143 Investigating the Torricelli point of a triangle - - - -
144 Investigating multiple reflections of a laser beam. - - - -
145 How many reversible numbers are there below one-billion? - - - -
146 Investigating a Prime Pattern - - - -
147 Rectangles in cross-hatched grids - - - -
148 Exploring Pascal's triangle. - - - -
149 Searching for a maximum-sum subsequence. - - - -
150 Searching a triangular array for a sub-triangle having minimum-sum. - - - -
151 Paper sheets of standard sizes: an expected-value problem. - - - -
152 Writing 1/2 as a sum of inverse squares - - - -
153 Investigating Gaussian Integers - - - -
154 Exploring Pascal&#39;s pyramid. - - - -
155 Counting Capacitor Circuits. - - - -
156 Counting Digits - - - -
157 Solving the diophantine equation <sup>1</sup>/<sub><var>a</var></sub>+<sup>1</sup>/<sub><var>b</var></sub>= <sup><var>p</var></sup>/<sub>10<sup><var>n</var></sup></sub> - - - -
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 - - - -
161 Triominoes - - - -
162 Hexadecimal numbers - 0.428 0.02 -
163 Cross-hatched triangles - - - -
164 Numbers for which no three consecutive digits have a sum greater than a given value. - - - -
165 Intersections - - - -
166 Criss Cross - - - -
167 Investigating Ulam sequences - - - -
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? - - - -
174 Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements. - - - -
175 Fractions involving the number of different ways a number can be expressed as a sum of powers of 2. - - - -
176 Rectangular triangles that share a cathetus. - - - -
177 Integer angled Quadrilaterals. - - - -
178 Step Numbers - - - -
179 Consecutive positive divisors - - - -
180 Rational zeros of a function of three variables. - - - -
181 Investigating in how many ways objects of two different colours can be grouped. - - - -
182 RSA encryption - - - -
183 Maximum product of parts - - - -
184 Triangles containing the origin. - - - -
185 Number Mind - - - -
186 Connectedness of a network. - - - -
187 Semiprimes - - - -
188 The hyperexponentiation of a number - - - -
189 Tri-colouring a triangular grid - - - -
190 Maximising a weighted product - - - -
191 Prize Strings - - - -
192 Best Approximations - - - -
193 Squarefree Numbers - - - -
194 Coloured Configurations - - - -
195 Inscribed circles of triangles with one angle of 60 degrees - - - -
196 Prime triplets - - - -
197 Investigating the behaviour of a recursively defined sequence - - - -
198 Ambiguous Numbers - - - -
199 Iterative Circle Packing - - - -
200 Find the 200th prime-proof sqube containing the contiguous sub-string "200" - - - -
201 Subsets with a unique sum - - - -
202 Laserbeam - - - -
203 Squarefree Binomial Coefficients - - - -
204 Generalised Hamming Numbers - 4.476 - -
205 Dice Game - 2.722 - -
206 Concealed Square - - - -
207 Integer partition equations - - - -
208 Robot Walks - - - -
209 Circular Logic - - - -
210 Obtuse Angled Triangles - - - -
211 Divisor Square Sum - - - -
212 Combined Volume of Cuboids - - - -
213 Flea Circus - - - -
214 Totient Chains - - - -
215 Crack-free Walls - - - -
216 Investigating the primality of numbers of the form 2<var>n</var><sup>2</sup>-1 - - - -
217 Balanced Numbers - - - -
218 Perfect right-angled triangles - - - -
219 Skew-cost coding - - - -
220 Heighway Dragon - - - -
221 Alexandrian Integers - - - -
222 Sphere Packing - - - -
223 Almost right-angled triangles I - - - -
224 Almost right-angled triangles II - - - -
225 Tribonacci non-divisors - - - -
226 A Scoop of Blancmange - - - -
227 The Chase - - - -
228 Minkowski Sums - - - -
229 Four Representations using Squares - - - -
230 Fibonacci Words - - - -
231 The prime factorisation of binomial coefficients - - - -
232 The Race - - - -
233 Lattice points on a circle - - - -
234 Semidivisible numbers - - - -
235 An Arithmetic Geometric sequence - - - -
236 Luxury Hampers - - - -
237 Tours on a 4 x n playing board - - - -
238 Infinite string tour - - - -
239 Twenty-two Foolish Primes - - - -
240 Top Dice - - - -
241 Perfection Quotients - - - -
242 Odd Triplets - - - -
243 Resilience - - - -
244 Sliders - - - -
245 Coresilience - - - -
246 Tangents to an ellipse - - - -
247 Squares under a hyperbola - - - -
248 Numbers for which Euler’s totient function equals 13! - - - -
249 Prime Subset Sums - - - -
250 250250 - - - -
251 Cardano Triplets - - - -
252 Convex Holes - - - -