fix(curriculum): clean-up Project Euler 141-160 (#42750)
* fix: clean-up Project Euler 141-160 * fix: corrections from review Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> * fix: corrections from review Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> * fix: use different notation for consistency * Update curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-144-investigating-multiple-reflections-of-a-laser-beam.md Co-authored-by: gikf <60067306+gikf@users.noreply.github.com> Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
@ -8,22 +8,22 @@ dashedName: problem-141-investigating-progressive-numbers-n-which-are-also-squar
|
||||
|
||||
# --description--
|
||||
|
||||
A positive integer, n, is divided by d and the quotient and remainder are q and r respectively. In addition d, q, and r are consecutive positive integer terms in a geometric sequence, but not necessarily in that order.
|
||||
A positive integer, $n$, is divided by $d$ and the quotient and remainder are $q$ and $r$ respectively. In addition $d$, $q$, and $r$ are consecutive positive integer terms in a geometric sequence, but not necessarily in that order.
|
||||
|
||||
For example, 58 divided by 6 has quotient 9 and remainder 4. It can also be seen that 4, 6, 9 are consecutive terms in a geometric sequence (common ratio 3/2).
|
||||
For example, 58 divided by 6 has a quotient of 9 and a remainder of 4. It can also be seen that 4, 6, 9 are consecutive terms in a geometric sequence (common ratio $\frac{3}{2}$).
|
||||
|
||||
We will call such numbers, n, progressive.
|
||||
We will call such numbers, $n$, progressive.
|
||||
|
||||
Some progressive numbers, such as 9 and 10404 = 1022, happen to also be perfect squares. The sum of all progressive perfect squares below one hundred thousand is 124657.
|
||||
Some progressive numbers, such as 9 and 10404 = ${102}^2$, also happen to be perfect squares. The sum of all progressive perfect squares below one hundred thousand is 124657.
|
||||
|
||||
Find the sum of all progressive perfect squares below one trillion (1012).
|
||||
Find the sum of all progressive perfect squares below one trillion (${101}^2$).
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler141()` should return 878454337159.
|
||||
`progressivePerfectSquares()` should return `878454337159`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler141(), 878454337159);
|
||||
assert.strictEqual(progressivePerfectSquares(), 878454337159);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +31,12 @@ assert.strictEqual(euler141(), 878454337159);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler141() {
|
||||
function progressivePerfectSquares() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler141();
|
||||
progressivePerfectSquares();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,14 +8,14 @@ dashedName: problem-142-perfect-square-collection
|
||||
|
||||
# --description--
|
||||
|
||||
Find the smallest x + y + z with integers x > y > z > 0 such that x + y, x − y, x + z, x − z, y + z, y − z are all perfect squares.
|
||||
Find the smallest $x + y + z$ with integers $x > y > z > 0$ such that $x + y$, $x − y$, $x + z$, $x − z$, $y + z$, $y − z$ are all perfect squares.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler142()` should return 1006193.
|
||||
`perfectSquareCollection()` should return `1006193`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler142(), 1006193);
|
||||
assert.strictEqual(perfectSquareCollection(), 1006193);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -23,12 +23,12 @@ assert.strictEqual(euler142(), 1006193);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler142() {
|
||||
function perfectSquareCollection() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler142();
|
||||
perfectSquareCollection();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,22 @@ dashedName: problem-143-investigating-the-torricelli-point-of-a-triangle
|
||||
|
||||
# --description--
|
||||
|
||||
Let ABC be a triangle with all interior angles being less than 120 degrees. Let X be any point inside the triangle and let XA = p, XC = q, and XB = r.
|
||||
Let ABC be a triangle with all interior angles being less than 120 degrees. Let X be any point inside the triangle and let $XA = p$, $XC = q$, and $XB = r$.
|
||||
|
||||
Fermat challenged Torricelli to find the position of X such that p + q + r was minimised.
|
||||
|
||||
Torricelli was able to prove that if equilateral triangles AOB, BNC and AMC are constructed on each side of triangle ABC, the circumscribed circles of AOB, BNC, and AMC will intersect at a single point, T, inside the triangle. Moreover he proved that T, called the Torricelli/Fermat point, minimises p + q + r. Even more remarkable, it can be shown that when the sum is minimised, AN = BM = CO = p + q + r and that AN, BM and CO also intersect at T.
|
||||
Torricelli was able to prove that if equilateral triangles AOB, BNC and AMC are constructed on each side of triangle ABC, the circumscribed circles of AOB, BNC, and AMC will intersect at a single point, T, inside the triangle. Moreover he proved that T, called the Torricelli/Fermat point, minimises $p + q + r$. Even more remarkable, it can be shown that when the sum is minimised, $AN = BM = CO = p + q + r$ and that AN, BM and CO also intersect at T.
|
||||
|
||||
If the sum is minimised and a, b, c, p, q and r are all positive integers we shall call triangle ABC a Torricelli triangle. For example, a = 399, b = 455, c = 511 is an example of a Torricelli triangle, with p + q + r = 784. Find the sum of all distinct values of p + q + r ≤ 120000 for Torricelli triangles.
|
||||
<img class="img-responsive center-block" alt="equilateral triangles AOB, BNC and AMC constructed on each side of triangle ABC; with the circumscribed circles of AOB, BNC, and AMC will intersecting at a single point, T, inside the triangle" src="https://cdn.freecodecamp.org/curriculum/project-euler/investigating-the-torricelli-point-of-a-triangle.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
If the sum is minimised and a, b, c, p, q and r are all positive integers we shall call triangle ABC a Torricelli triangle. For example, $a = 399$, $b = 455$, $c = 511$ is an example of a Torricelli triangle, with $p + q + r = 784$. Find the sum of all distinct values of $p + q + r ≤ 120000$ for Torricelli triangles.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler143()` should return 30758397.
|
||||
`sumTorricelliTriangles()` should return `30758397`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler143(), 30758397);
|
||||
assert.strictEqual(sumTorricelliTriangles(), 30758397);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +31,12 @@ assert.strictEqual(euler143(), 30758397);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler143() {
|
||||
function sumTorricelliTriangles() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler143();
|
||||
sumTorricelliTriangles();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,20 +10,35 @@ dashedName: problem-144-investigating-multiple-reflections-of-a-laser-beam
|
||||
|
||||
In laser physics, a "white cell" is a mirror system that acts as a delay line for the laser beam. The beam enters the cell, bounces around on the mirrors, and eventually works its way back out.
|
||||
|
||||
The specific white cell we will be considering is an ellipse with the equation 4x2 + y2 = 100
|
||||
The specific white cell we will be considering is an ellipse with the equation $4{x}^2 + y^2 = 100$
|
||||
|
||||
The section corresponding to −0.01 ≤ x ≤ +0.01 at the top is missing, allowing the light to enter and exit through the hole.
|
||||
The section corresponding to $−0.01 ≤ x ≤ +0.01$ at the top is missing, allowing the light to enter and exit through the hole.
|
||||
|
||||
The light beam in this problem starts at the point (0.0,10.1) just outside the white cell, and the beam first impacts the mirror at (1.4,-9.6). Each time the laser beam hits the surface of the ellipse, it follows the usual law of reflection "angle of incidence equals angle of reflection." That is, both the incident and reflected beams make the same angle with the normal line at the point of incidence. In the figure on the left, the red line shows the first two points of contact between the laser beam and the wall of the white cell; the blue line shows the line tangent to the ellipse at the point of incidence of the first bounce.The slope m of the tangent line at any point (x,y) of the given ellipse is: m = −4x/yThe normal line is perpendicular to this tangent line at the point of incidence. The animation on the right shows the first 10 reflections of the beam.
|
||||
<div style="text-align: center">
|
||||
<img class="img-responsive center-block" alt="light beam starting at point (0.0, 10.1), and impacing the mirror at point (1.4, -9.6)" src="https://cdn.freecodecamp.org/curriculum/project-euler/investigating-multiple-reflections-of-a-laser-beam-1.png" style="display: inline-block; background-color: white; padding: 10px;">
|
||||
<img class="img-responsive center-block" alt="animation with first 10 relfections of the beam" src="https://cdn.freecodecamp.org/curriculum/project-euler/investigating-multiple-reflections-of-a-laser-beam-2.gif" style="display: inline-block; background-color: white; padding: 10px;">
|
||||
</div><br>
|
||||
|
||||
The light beam in this problem starts at the point (0.0, 10.1) just outside the white cell, and the beam first impacts the mirror at (1.4, -9.6).
|
||||
|
||||
Each time the laser beam hits the surface of the ellipse, it follows the usual law of reflection "angle of incidence equals angle of reflection." That is, both the incident and reflected beams make the same angle with the normal line at the point of incidence.
|
||||
|
||||
In the figure on the left, the red line shows the first two points of contact between the laser beam and the wall of the white cell; the blue line shows the line tangent to the ellipse at the point of incidence of the first bounce.
|
||||
|
||||
The slope m of the tangent line at any point (x, y) of the given ellipse is: $m = −4 × \frac{x}{y}$
|
||||
|
||||
The normal line is perpendicular to this tangent line at the point of incidence.
|
||||
|
||||
The animation on the right shows the first 10 reflections of the beam.
|
||||
|
||||
How many times does the beam hit the internal surface of the white cell before exiting?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler144()` should return 354.
|
||||
`laserBeamReflections()` should return `354`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler144(), 354);
|
||||
assert.strictEqual(laserBeamReflections(), 354);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +46,12 @@ assert.strictEqual(euler144(), 354);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler144() {
|
||||
function laserBeamReflections() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler144();
|
||||
laserBeamReflections();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-145-how-many-reversible-numbers-are-there-below-one-billion
|
||||
|
||||
# --description--
|
||||
|
||||
Some positive integers n have the property that the sum \[ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).
|
||||
Some positive integers $n$ have the property that the sum [ $n + reverse(n)$ ] consists entirely of odd (decimal) digits. For instance, $36 + 63 = 99$ and $409 + 904 = 1313$. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either $n$ or $reverse(n)$.
|
||||
|
||||
There are 120 reversible numbers below one-thousand.
|
||||
|
||||
How many reversible numbers are there below one-billion (109)?
|
||||
How many reversible numbers are there below one-billion (${10}^9$)?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler145()` should return 608720.
|
||||
`reversibleNumbers()` should return `608720`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler145(), 608720);
|
||||
assert.strictEqual(reversibleNumbers(), 608720);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler145(), 608720);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler145() {
|
||||
function reversibleNumbers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler145();
|
||||
reversibleNumbers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,16 +8,16 @@ dashedName: problem-146-investigating-a-prime-pattern
|
||||
|
||||
# --description--
|
||||
|
||||
The smallest positive integer n for which the numbers n2+1, n2+3, n2+7, n2+9, n2+13, and n2+27 are consecutive primes is 10. The sum of all such integers n below one-million is 1242490.
|
||||
The smallest positive integer $n$ for which the numbers $n^2 + 1$, $n^2 + 3$, $n^2 + 7$, $n^2 + 9$, $n^2 + 13$, and $n^2 + 27$ are consecutive primes is 10. The sum of all such integers $n$ below one-million is 1242490.
|
||||
|
||||
What is the sum of all such integers n below 150 million?
|
||||
What is the sum of all such integers $n$ below 150 million?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler146()` should return 676333270.
|
||||
`primePattern()` should return `676333270`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler146(), 676333270);
|
||||
assert.strictEqual(primePattern(), 676333270);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -25,12 +25,12 @@ assert.strictEqual(euler146(), 676333270);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler146() {
|
||||
function primePattern() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler146();
|
||||
primePattern();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,7 +10,18 @@ dashedName: problem-147-rectangles-in-cross-hatched-grids
|
||||
|
||||
In a 3x2 cross-hatched grid, a total of 37 different rectangles could be situated within that grid as indicated in the sketch.
|
||||
|
||||
There are 5 grids smaller than 3x2, vertical and horizontal dimensions being important, i.e. 1x1, 2x1, 3x1, 1x2 and 2x2. If each of them is cross-hatched, the following number of different rectangles could be situated within those smaller grids: 1x1: 1 2x1: 4 3x1: 8 1x2: 4 2x2: 18
|
||||
<img class="img-responsive center-block" alt="ways of situating different rectangles wihtin cross-hatched 3x2 grid" src="https://cdn.freecodecamp.org/curriculum/project-euler/rectangles-in-cross-hatched-grids.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
There are 5 grids smaller than 3x2, vertical and horizontal dimensions being important, i.e. 1x1, 2x1, 3x1, 1x2 and 2x2. If each of them is cross-hatched, the following number of different rectangles could be situated within those smaller grids:
|
||||
|
||||
$$\begin{array}{|c|c|}
|
||||
\hline
|
||||
1 \times 1 & 1 \\\\ \hline
|
||||
2 \times 1 & 4 \\\\ \hline
|
||||
3 \times 1 & 8 \\\\ \hline
|
||||
1 \times 2 & 4 \\\\ \hline
|
||||
2 \times 2 & 18 \\\\ \hline
|
||||
\end{array}$$
|
||||
|
||||
Adding those to the 37 of the 3x2 grid, a total of 72 different rectangles could be situated within 3x2 and smaller grids.
|
||||
|
||||
@ -18,10 +29,10 @@ How many different rectangles could be situated within 47x43 and smaller grids?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler147()` should return 846910284.
|
||||
`crossHatchedRectangles()` should return `846910284`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler147(), 846910284);
|
||||
assert.strictEqual(crossHatchedRectangles(), 846910284);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +40,12 @@ assert.strictEqual(euler147(), 846910284);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler147() {
|
||||
function crossHatchedRectangles() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler147();
|
||||
crossHatchedRectangles();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,7 +10,7 @@ dashedName: problem-148-exploring-pascals-triangle
|
||||
|
||||
We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by 7:
|
||||
|
||||
<pre>
|
||||
```
|
||||
1
|
||||
1 1
|
||||
1 2 1
|
||||
@ -18,20 +18,20 @@ We can easily verify that none of the entries in the first seven rows of Pascal'
|
||||
1 4 6 4 1
|
||||
1 5 10 10 5 1
|
||||
1 6 15 20 15 6 1
|
||||
</pre>
|
||||
```
|
||||
|
||||
However, if we check the first one hundred rows, we will find that only 2361 of the 5050 entries are not divisible by 7.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Find the number of entries which are not divisible by 7 in the first one billion (10<sup>9</sup>) rows of Pascal's triangle.
|
||||
Find the number of entries which are not divisible by 7 in the first one billion (${10}^9$) rows of Pascal's triangle.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler148()` should return 2129970655314432.
|
||||
`entriesOfPascalsTriangle()` should return `2129970655314432`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler148(), 2129970655314432);
|
||||
assert.strictEqual(entriesOfPascalsTriangle(), 2129970655314432);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -39,12 +39,12 @@ assert.strictEqual(euler148(), 2129970655314432);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler148() {
|
||||
function entriesOfPascalsTriangle() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler148();
|
||||
entriesOfPascalsTriangle();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,28 +8,36 @@ dashedName: problem-149-searching-for-a-maximum-sum-subsequence
|
||||
|
||||
# --description--
|
||||
|
||||
Looking at the table below, it is easy to verify that the maximum possible sum of adjacent numbers in any direction (horizontal, vertical, diagonal or anti-diagonal) is 16 (= 8 + 7 + 1).
|
||||
Looking at the table below, it is easy to verify that the maximum possible sum of adjacent numbers in any direction (horizontal, vertical, diagonal or anti-diagonal) is $16 (= 8 + 7 + 1)$.
|
||||
|
||||
−25329−6513273−18−4 8
|
||||
$$\begin{array}{|r|r|r|r|}
|
||||
\hline
|
||||
−2 & 5 & 3 & 2 \\\\ \hline
|
||||
9 & −6 & 5 & 1 \\\\ \hline
|
||||
3 & 2 & 7 & 3 \\\\ \hline
|
||||
−1 & 8 & −4 & 8 \\\\ \hline
|
||||
\end{array}$$
|
||||
|
||||
Now, let us repeat the search, but on a much larger scale:
|
||||
|
||||
First, generate four million pseudo-random numbers using a specific form of what is known as a "Lagged Fibonacci Generator":
|
||||
|
||||
For 1 ≤ k ≤ 55, sk = \[100003 − 200003k + 300007k3] (modulo 1000000) − 500000. For 56 ≤ k ≤ 4000000, sk = \[sk−24 + sk−55 + 1000000] (modulo 1000000) − 500000.
|
||||
For $1 ≤ k ≤ 55$, $s_k = (100003 − 200003k + 300007{k}^3) \\ (modulo\\ 1000000) − 500000$.
|
||||
|
||||
Thus, s10 = −393027 and s100 = 86613.
|
||||
For $56 ≤ k ≤ 4000000$, $s_k = (s_{k − 24} + s_{k − 55} + 1000000) \\ (modulo\\ 1000000) − 500000$.
|
||||
|
||||
The terms of s are then arranged in a 2000×2000 table, using the first 2000 numbers to fill the first row (sequentially), the next 2000 numbers to fill the second row, and so on.
|
||||
Thus, $s_{10} = −393027$ and $s_{100} = 86613$.
|
||||
|
||||
The terms of $s$ are then arranged in a 2000×2000 table, using the first 2000 numbers to fill the first row (sequentially), the next 2000 numbers to fill the second row, and so on.
|
||||
|
||||
Finally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler149()` should return 52852124.
|
||||
`maximumSubSequence()` should return `52852124`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler149(), 52852124);
|
||||
assert.strictEqual(maximumSubSequence(), 52852124);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -37,12 +45,12 @@ assert.strictEqual(euler149(), 52852124);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler149() {
|
||||
function maximumSubSequence() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler149();
|
||||
maximumSubSequence();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -14,15 +14,28 @@ In a triangular array of positive and negative integers, we wish to find a sub-t
|
||||
|
||||
In the example below, it can be easily verified that the marked triangle satisfies this condition having a sum of −42.
|
||||
|
||||
We wish to make such a triangular array with one thousand rows, so we generate 500500 pseudo-random numbers sk in the range ±219, using a type of random number generator (known as a Linear Congruential Generator) as follows: t := 0
|
||||
<img class="img-responsive center-block" alt="triangular array, with marked sub-triangle, having sum of -42" src="https://cdn.freecodecamp.org/curriculum/project-euler/searching-a-triangular-array-for-a-sub-triangle-having-minimum-sum.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
for k = 1 up to k = 500500:
|
||||
We wish to make such a triangular array with one thousand rows, so we generate 500500 pseudo-random numbers $s_k$ in the range $±2^{19}$, using a type of random number generator (known as a Linear Congruential Generator) as follows:
|
||||
|
||||
t := (615949\*t + 797807) modulo 220 sk := t−219 Thus: s1 = 273519, s2 = −153582, s3 = 450905 etc Our triangular array is then formed using the pseudo-random numbers thus:
|
||||
$$\begin{align}
|
||||
t := & \\ 0\\\\
|
||||
\text{for}\\ & k = 1\\ \text{up to}\\ k = 500500:\\\\
|
||||
& t := (615949 × t + 797807)\\ \text{modulo}\\ 2^{20}\\\\
|
||||
& s_k := t − 219\\\\
|
||||
\end{align}$$
|
||||
|
||||
s1 s2 s3 s4 s5 s6
|
||||
Thus: $s_1 = 273519$, $s_2 = −153582$, $s_3 = 450905$ etc.
|
||||
|
||||
s7 s8 s9 s10 ...
|
||||
Our triangular array is then formed using the pseudo-random numbers thus:
|
||||
|
||||
$$
|
||||
s_1 \\\\
|
||||
s_2\\;s_3 \\\\
|
||||
s_4\\; s_5\\; s_6 \\\\
|
||||
s_7\\; s_8\\; s_9\\; s_{10} \\\\
|
||||
\ldots
|
||||
$$
|
||||
|
||||
Sub-triangles can start at any element of the array and extend down as far as we like (taking-in the two elements directly below it from the next row, the three elements directly below from the row after that, and so on).
|
||||
|
||||
@ -32,10 +45,10 @@ Find the smallest possible sub-triangle sum.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler150()` should return -271248680.
|
||||
`smallestSubTriangleSum()` should return `-271248680`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler150(), -271248680);
|
||||
assert.strictEqual(smallestSubTriangleSum(), -271248680);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -43,12 +56,12 @@ assert.strictEqual(euler150(), -271248680);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler150() {
|
||||
function smallestSubTriangleSum() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler150();
|
||||
smallestSubTriangleSum();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -16,14 +16,20 @@ He proceeds to cut it in half, thus getting two sheets of size A2. Then he cuts
|
||||
|
||||
All the unused sheets are placed back in the envelope.
|
||||
|
||||
At the beginning of each subsequent batch, he takes from the envelope one sheet of paper at random. If it is of size A5, he uses it. If it is larger, he repeats the 'cut-in-half' procedure until he has what he needs and any remaining sheets are always placed back in the envelope. Excluding the first and last batch of the week, find the expected number of times (during each week) that the foreman finds a single sheet of paper in the envelope. Give your answer rounded to six decimal places using the format x.xxxxxx .
|
||||
<img class="img-responsive center-block" alt="A1-size sheet split into: A2, A3, A4 and two A5 sheets" src="https://cdn.freecodecamp.org/curriculum/project-euler/paper-sheets-of-standard-sizes-an-expected-value-problem.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
At the beginning of each subsequent batch, he takes one sheet of paper from the envelope at random. If it is of size A5, he uses it. If it is larger, he repeats the 'cut-in-half' procedure until he has what he needs, and any remaining sheets are always placed back in the envelope.
|
||||
|
||||
Excluding the first and last batch of the week, find the expected number of times (during each week) that the foreman finds a single sheet of paper in the envelope.
|
||||
|
||||
Give your answer rounded to six decimal places using the format `x.xxxxxx`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler151()` should return 0.464399.
|
||||
`expectedValueProblem()` should return `0.464399`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler151(), 0.464399);
|
||||
assert.strictEqual(expectedValueProblem(), 0.464399);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +37,12 @@ assert.strictEqual(euler151(), 0.464399);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler151() {
|
||||
function expectedValueProblem() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler151();
|
||||
expectedValueProblem();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,22 @@ dashedName: problem-152-writing-one-half-as-a-sum-of-inverse-squares
|
||||
|
||||
# --description--
|
||||
|
||||
There are several ways to write the number 1/2 as a sum of inverse squares using distinct integers.
|
||||
There are several ways to write the number $\frac{1}{2}$ as a sum of inverse squares using distinct integers.
|
||||
|
||||
For instance, the numbers {2,3,4,5,7,12,15,20,28,35} can be used:
|
||||
|
||||
In fact, only using integers between 2 and 45 inclusive, there are exactly three ways to do it, the remaining two being: {2,3,4,6,7,9,10,20,28,35,36,45} and {2,3,4,6,7,9,12,15,28,30,35,36,45}. How many ways are there to write the number 1/2 as a sum of inverse squares using distinct integers between 2 and 80 inclusive?
|
||||
$$\frac{1}{2} = \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \frac{1}{5^2} + \frac{1}{7^2} + \frac{1}{{12}^2} + \frac{1}{{15}^2} + \frac{1}{{20}^2} + \frac{1}{{28}^2} + \frac{1}{{35}^2}$$
|
||||
|
||||
In fact, only using integers between 2 and 45 inclusive, there are exactly three ways to do it, the remaining two being: {2,3,4,6,7,9,10,20,28,35,36,45} and {2,3,4,6,7,9,12,15,28,30,35,36,45}.
|
||||
|
||||
How many ways are there to write the number $\frac{1}{2}$ as a sum of inverse squares using distinct integers between 2 and 80 inclusive?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler152()` should return 301.
|
||||
`sumInverseSquares()` should return `301`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler152(), 301);
|
||||
assert.strictEqual(sumInverseSquares(), 301);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +31,12 @@ assert.strictEqual(euler152(), 301);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler152() {
|
||||
function sumInverseSquares() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler152();
|
||||
sumInverseSquares();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,46 +8,60 @@ dashedName: problem-153-investigating-gaussian-integers
|
||||
|
||||
# --description--
|
||||
|
||||
As we all know the equation x2=-1 has no solutions for real x.
|
||||
As we all know the equation $x^2 = -1$ has no solutions for real $x$.
|
||||
|
||||
If we however introduce the imaginary number i this equation has two solutions: x=i and x=-i.
|
||||
If we however introduce the imaginary number $i$ this equation has two solutions: $x = i$ and $x = -i$.
|
||||
|
||||
If we go a step further the equation (x-3)2=-4 has two complex solutions: x=3+2i and x=3-2i. x=3+2i and x=3-2i are called each others' complex conjugate.
|
||||
If we go a step further the equation ${(x - 3)}^2 = -4$ has two complex solutions: $x = 3 + 2i$ and $x = 3 - 2i$, which are called each others' complex conjugate.
|
||||
|
||||
Numbers of the form a+bi are called complex numbers.
|
||||
Numbers of the form $a + bi$ are called complex numbers.
|
||||
|
||||
In general a+bi and a−bi are each other's complex conjugate. A Gaussian Integer is a complex number a+bi such that both a and b are integers.
|
||||
In general $a + bi$ and $a − bi$ are each other's complex conjugate. A Gaussian Integer is a complex number $a + bi$ such that both $a$ and $b$ are integers.
|
||||
|
||||
The regular integers are also Gaussian integers (with b=0).
|
||||
The regular integers are also Gaussian integers (with $b = 0$).
|
||||
|
||||
To distinguish them from Gaussian integers with b ≠ 0 we call such integers "rational integers."
|
||||
To distinguish them from Gaussian integers with $b ≠ 0$ we call such integers "rational integers."
|
||||
|
||||
A Gaussian integer is called a divisor of a rational integer n if the result is also a Gaussian integer.
|
||||
A Gaussian integer is called a divisor of a rational integer $n$ if the result is also a Gaussian integer.
|
||||
|
||||
If for example we divide 5 by 1+2i we can simplify in the following manner:
|
||||
If for example we divide 5 by $1 + 2i$ we can simplify in the following manner:
|
||||
|
||||
Multiply numerator and denominator by the complex conjugate of 1+2i: 1−2i.
|
||||
Multiply numerator and denominator by the complex conjugate of $1 + 2i$: $1 − 2i$.
|
||||
|
||||
The result is .
|
||||
The result is:
|
||||
|
||||
So 1+2i is a divisor of 5.
|
||||
$$\frac{5}{1 + 2i} = \frac{5}{1 + 2i} \frac{1 - 2i}{1 - 2i} = \frac{5(1 - 2i)}{1 - {(2i)}^2} = \frac{5(1 - 2i)}{1 - (-4)} = \frac{5(1 - 2i)}{5} = 1 - 2i$$
|
||||
|
||||
Note that 1+i is not a divisor of 5 because .
|
||||
So $1 + 2i$ is a divisor of 5.
|
||||
|
||||
Note also that if the Gaussian Integer (a+bi) is a divisor of a rational integer n, then its complex conjugate (a−bi) is also a divisor of n. In fact, 5 has six divisors such that the real part is positive: {1, 1 + 2i, 1 − 2i, 2 + i, 2 − i, 5}.
|
||||
Note that $1 + i$ is not a divisor of 5 because:
|
||||
|
||||
$$\frac{5}{1 + i} = \frac{5}{2} - \frac{5}{2}i$$
|
||||
|
||||
Note also that if the Gaussian Integer ($a + bi$) is a divisor of a rational integer $n$, then its complex conjugate ($a − bi$) is also a divisor of $n$. In fact, 5 has six divisors such that the real part is positive: {1, 1 + 2i, 1 − 2i, 2 + i, 2 − i, 5}.
|
||||
|
||||
The following is a table of all of the divisors for the first five positive rational integers:
|
||||
|
||||
n Gaussian integer divisors with positive real partSum s(n) of these
|
||||
| n | Gaussian integer divisors with positive real part | Sum s(n) of these divisors |
|
||||
|---|---------------------------------------------------|----------------------------|
|
||||
| 1 | 1 | 1 |
|
||||
| 2 | 1, 1 + i, 1 - i, 2 | 5 |
|
||||
| 3 | 1, 3 | 4 |
|
||||
| 4 | 1, 1 + i, 1 - i, 2, 2 + 2i, 2 - 2i, 4 | 13 |
|
||||
| 5 | 1, 1 + 2i, 1 - 2i, 2 + i, 2 - i, 5 | 12 |
|
||||
|
||||
divisors111 21, 1+i, 1-i, 25 31, 34 41, 1+i, 1-i, 2, 2+2i, 2-2i,413 51, 1+2i, 1-2i, 2+i, 2-i, 512 For divisors with positive real parts, then, we have: . For 1 ≤ n ≤ 105, ∑ s(n)=17924657155. What is ∑ s(n) for 1 ≤ n ≤ 108?
|
||||
For divisors with positive real parts, then, we have: $\displaystyle\sum_{n=1}^5 s(n) = 35$.
|
||||
|
||||
For $1 ≤ n ≤ {10}^5$, $\displaystyle\sum_{n = 1}^{{10}^5} s(n) = 17924657155$.
|
||||
|
||||
What is $\displaystyle\sum_{n=1}^{{10}^8} s(n)$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler153()` should return 17971254122360636.
|
||||
`sumGaussianIntegers()` should return `17971254122360636`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler153(), 17971254122360636);
|
||||
assert.strictEqual(sumGaussianIntegers(), 17971254122360636);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -55,12 +69,12 @@ assert.strictEqual(euler153(), 17971254122360636);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler153() {
|
||||
function sumGaussianIntegers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler153();
|
||||
sumGaussianIntegers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,14 +10,20 @@ dashedName: problem-154-exploring-pascals-pyramid
|
||||
|
||||
A triangular pyramid is constructed using spherical balls so that each ball rests on exactly three balls of the next lower level.
|
||||
|
||||
Then, we calculate the number of paths leading from the apex to each position: A path starts at the apex and progresses downwards to any of the three spheres directly below the current position. Consequently, the number of paths to reach a certain position is the sum of the numbers immediately above it (depending on the position, there are up to three numbers above it). The result is Pascal's pyramid and the numbers at each level n are the coefficients of the trinomial expansion (x + y + z)n. How many coefficients in the expansion of (x + y + z)200000 are multiples of 1012?
|
||||
<img class="img-responsive center-block" alt="triangular pyramid constructed using spherical balls with four levels" src="https://cdn.freecodecamp.org/curriculum/project-euler/exploring-pascals-pyramid.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
Then, we calculate the number of paths leading from the apex to each position: A path starts at the apex and progresses downwards to any of the three spheres directly below the current position. Consequently, the number of paths to reach a certain position is the sum of the numbers immediately above it (depending on the position, there are up to three numbers above it).
|
||||
|
||||
The result is Pascal's pyramid and the numbers at each level n are the coefficients of the trinomial expansion ${(x + y + z)}^n$.
|
||||
|
||||
How many coefficients in the expansion of ${(x + y + z)}^{200000}$ are multiples of ${10}^{12}$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler154()` should return 479742450.
|
||||
`pascalsPyramid()` should return `479742450`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler154(), 479742450);
|
||||
assert.strictEqual(pascalsPyramid(), 479742450);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -25,12 +31,12 @@ assert.strictEqual(euler154(), 479742450);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler154() {
|
||||
function pascalsPyramid() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler154();
|
||||
pascalsPyramid();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,18 +10,24 @@ dashedName: problem-155-counting-capacitor-circuits
|
||||
|
||||
An electric circuit uses exclusively identical capacitors of the same value C.
|
||||
|
||||
The capacitors can be connected in series or in parallel to form sub-units, which can then be connected in series or in parallel with other capacitors or other sub-units to form larger sub-units, and so on up to a final circuit. Using this simple procedure and up to n identical capacitors, we can make circuits having a range of different total capacitances. For example, using up to n=3 capacitors of 60 F each, we can obtain the following 7 distinct total capacitance values:
|
||||
The capacitors can be connected in series or in parallel to form sub-units, which can then be connected in series or in parallel with other capacitors or other sub-units to form larger sub-units, and so on up to a final circuit.
|
||||
|
||||
If we denote by D(n) the number of distinct total capacitance values we can obtain when using up to n equal-valued capacitors and the simple procedure described above, we have: D(1)=1, D(2)=3, D(3)=7 ... Find D(18). Reminder : When connecting capacitors C1, C2 etc in parallel, the total capacitance is CT = C1 + C2 +...,
|
||||
Using this simple procedure and up to n identical capacitors, we can make circuits having a range of different total capacitances. For example, using up to $n = 3$ capacitors of $60 μF$ each, we can obtain the following 7 distinct total capacitance values:
|
||||
|
||||
whereas when connecting them in series, the overall capacitance is given by:
|
||||
<img class="img-responsive center-block" alt="example circuits having up to three capacitors, each of 60 μF" src="https://cdn.freecodecamp.org/curriculum/project-euler/counting-capacitor-circuits.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
If we denote by $D(n)$ the number of distinct total capacitance values we can obtain when using up to $n$ equal-valued capacitors and the simple procedure described above, we have: $D(1) = 1, D(2) = 3, D(3)=7, \ldots$
|
||||
|
||||
Find $D(18)$.
|
||||
|
||||
Reminder: When connecting capacitors $C_1$, $C_2$ etc in parallel, the total capacitance is $C_T = C_1 + C_2 + \cdots$, whereas when connecting them in series, the overall capacitance is given by: $\frac{1}{C_T} = \frac{1}{C_1} + \frac{1}{C_2} + \cdots$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler155()` should return 3857447.
|
||||
`capacitanceValues()` should return `3857447`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler155(), 3857447);
|
||||
assert.strictEqual(capacitanceValues(), 3857447);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +35,12 @@ assert.strictEqual(euler155(), 3857447);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler155() {
|
||||
function capacitanceValues() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler155();
|
||||
capacitanceValues();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,24 +12,40 @@ Starting from zero the natural numbers are written down in base 10 like this:
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12....
|
||||
|
||||
Consider the digit d=1. After we write down each number n, we will update the number of ones that have occurred and call this number f(n,1). The first values for f(n,1), then, are as follows:
|
||||
Consider the digit $d = 1$. After we write down each number n, we will update the number of ones that have occurred and call this number $f(n, 1)$. The first values for $f(n, 1)$, then, are as follows:
|
||||
|
||||
nf(n,1) 00 11 21 31 41 51 61 71 81 91 102 114 125
|
||||
| $n$ | $f(n, 1)$ |
|
||||
|-----|-----------|
|
||||
| 0 | 0 |
|
||||
| 1 | 1 |
|
||||
| 2 | 1 |
|
||||
| 3 | 1 |
|
||||
| 4 | 1 |
|
||||
| 5 | 1 |
|
||||
| 6 | 1 |
|
||||
| 7 | 1 |
|
||||
| 8 | 1 |
|
||||
| 9 | 1 |
|
||||
| 10 | 2 |
|
||||
| 11 | 4 |
|
||||
| 12 | 5 |
|
||||
|
||||
Note that f(n,1) never equals 3.
|
||||
Note that $f(n, 1)$ never equals 3.
|
||||
|
||||
So the first two solutions of the equation f(n,1)=n are n=0 and n=1. The next solution is n=199981. In the same manner the function f(n,d) gives the total number of digits d that have been written down after the number n has been written.
|
||||
So the first two solutions of the equation $f(n, 1) = n$ are $n = 0$ and $n = 1$. The next solution is $n = 199981$. In the same manner the function $f(n, d)$ gives the total number of digits d that have been written down after the number $n$ has been written.
|
||||
|
||||
In fact, for every digit d ≠ 0, 0 is the first solution of the equation f(n,d)=n. Let s(d) be the sum of all the solutions for which f(n,d)=n.
|
||||
In fact, for every digit $d ≠ 0$, 0 is the first solution of the equation $f(n, d) = n$. Let $s(d)$ be the sum of all the solutions for which $f(n, d) = n$.
|
||||
|
||||
You are given that s(1)=22786974071. Find ∑ s(d) for 1 ≤ d ≤ 9. Note: if, for some n, f(n,d)=n for more than one value of d this value of n is counted again for every value of d for which f(n,d)=n.
|
||||
You are given that $s(1) = 22786974071$. Find $\sum{s(d)}$ for $1 ≤ d ≤ 9$.
|
||||
|
||||
Note: if, for some $n$, $f(n, d) = n$ for more than one value of $d$ this value of $n$ is counted again for every value of $d$ for which $f(n, d) = n$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler156()` should return 21295121502550.
|
||||
`countingDigits()` should return `21295121502550`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler156(), 21295121502550);
|
||||
assert.strictEqual(countingDigits(), 21295121502550);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -37,12 +53,12 @@ assert.strictEqual(euler156(), 21295121502550);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler156() {
|
||||
function countingDigits() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler156();
|
||||
countingDigits();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,58 +8,33 @@ dashedName: problem-157-solving-the-diophantine-equation
|
||||
|
||||
# --description--
|
||||
|
||||
Consider the diophantine equation 1/a+1/b= p/10n with a, b, p, n positive integers and a ≤ b.
|
||||
Consider the diophantine equation $\frac{1}{a} + \frac{1}{b} = \frac{p}{{10}^n}$ with $a$, $b$, $p$, $n$ positive integers and $a ≤ b$.
|
||||
|
||||
For n=1 this equation has 20 solutions that are listed below:
|
||||
For $n = 1$ this equation has 20 solutions that are listed below:
|
||||
|
||||
1/1+1/1=20/10
|
||||
$$\begin{array}{lllll}
|
||||
\frac{1}{1} + \frac{1}{1} = \frac{20}{10} & \frac{1}{1} + \frac{1}{2} = \frac{15}{10}
|
||||
& \frac{1}{1} + \frac{1}{5} = \frac{12}{10} & \frac{1}{1} + \frac{1}{10} = \frac{11}{10}
|
||||
& \frac{1}{2} + \frac{1}{2} = \frac{10}{10} \\\\
|
||||
\frac{1}{2} + \frac{1}{5} = \frac{7}{10} & \frac{1}{2} + \frac{1}{10} = \frac{6}{10}
|
||||
& \frac{1}{3} + \frac{1}{6} = \frac{5}{10} & \frac{1}{3} + \frac{1}{15} = \frac{4}{10}
|
||||
& \frac{1}{4} + \frac{1}{4} = \frac{5}{10} \\\\
|
||||
\frac{1}{4} + \frac{1}{4} = \frac{5}{10} & \frac{1}{5} + \frac{1}{5} = \frac{4}{10}
|
||||
& \frac{1}{5} + \frac{1}{10} = \frac{3}{10} & \frac{1}{6} + \frac{1}{30} = \frac{2}{10}
|
||||
& \frac{1}{10} + \frac{1}{10} = \frac{2}{10} \\\\
|
||||
\frac{1}{11} + \frac{1}{110} = \frac{1}{10} & \frac{1}{12} + \frac{1}{60} = \frac{1}{10}
|
||||
& \frac{1}{14} + \frac{1}{35} = \frac{1}{10} & \frac{1}{15} + \frac{1}{30} = \frac{1}{10}
|
||||
& \frac{1}{20} + \frac{1}{20} = \frac{1}{10}
|
||||
\end{array}$$
|
||||
|
||||
1/1+1/2=15/10
|
||||
|
||||
1/1+1/5=12/10
|
||||
|
||||
1/1+1/10=11/10
|
||||
|
||||
1/2+1/2=10/10
|
||||
|
||||
1/2+1/5=7/10
|
||||
|
||||
1/2+1/10=6/10
|
||||
|
||||
1/3+1/6=5/10
|
||||
|
||||
1/3+1/15=4/10
|
||||
|
||||
1/4+1/4=5/10
|
||||
|
||||
1/4+1/20=3/10
|
||||
|
||||
1/5+1/5=4/10
|
||||
|
||||
1/5+1/10=3/10
|
||||
|
||||
1/6+1/30=2/10
|
||||
|
||||
1/10+1/10=2/10
|
||||
|
||||
1/11+1/110=1/10
|
||||
|
||||
1/12+1/60=1/10
|
||||
|
||||
1/14+1/35=1/10
|
||||
|
||||
1/15+1/30=1/10
|
||||
|
||||
1/20+1/20=1/10
|
||||
|
||||
How many solutions has this equation for 1 ≤ n ≤ 9?
|
||||
How many solutions has this equation for $1 ≤ n ≤ 9$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler157()` should return 53490.
|
||||
`diophantineEquation()` should return `53490`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler157(), 53490);
|
||||
assert.strictEqual(diophantineEquation(), 53490);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -67,12 +42,12 @@ assert.strictEqual(euler157(), 53490);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler157() {
|
||||
function diophantineEquation() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler157();
|
||||
diophantineEquation();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -21,18 +21,18 @@ For 'hat' there is exactly one character that comes lexicographically after its
|
||||
|
||||
In all there are 10400 strings of length 3 for which exactly one character comes lexicographically after its neighbour to the left.
|
||||
|
||||
We now consider strings of n ≤ 26 different characters from the alphabet.
|
||||
We now consider strings of $n ≤ 26$ different characters from the alphabet.
|
||||
|
||||
For every n, p(n) is the number of strings of length n for which exactly one character comes lexicographically after its neighbour to the left.
|
||||
For every $n$, $p(n)$ is the number of strings of length $n$ for which exactly one character comes lexicographically after its neighbour to the left.
|
||||
|
||||
What is the maximum value of p(n)?
|
||||
What is the maximum value of $p(n)$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler158()` should return 409511334375.
|
||||
`lexicographicNeighbours()` should return `409511334375`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler158(), 409511334375);
|
||||
assert.strictEqual(lexicographicNeighbours(), 409511334375);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -40,12 +40,12 @@ assert.strictEqual(euler158(), 409511334375);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler158() {
|
||||
function lexicographicNeighbours() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler158();
|
||||
lexicographicNeighbours();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,13 +12,37 @@ A composite number can be factored many different ways.
|
||||
|
||||
For instance, not including multiplication by one, 24 can be factored in 7 distinct ways:
|
||||
|
||||
24 = 2x2x2x3 24 = 2x3x4 24 = 2x2x6 24 = 4x6 24 = 3x8 24 = 2x12 24 = 24
|
||||
$$\begin{align}
|
||||
& 24 = 2 \times 2 \times 2 \times 3\\\\
|
||||
& 24 = 2 \times 3 \times 4 \\\\
|
||||
& 24 = 2 \times 2 \times 6 \\\\
|
||||
& 24 = 4 \times 6 \\\\
|
||||
& 24 = 3 \times 8 \\\\
|
||||
& 24 = 2 \times 12 \\\\
|
||||
& 24 = 24
|
||||
\end{align}$$
|
||||
|
||||
Recall that the digital root of a number, in base 10, is found by adding together the digits of that number, and repeating that process until a number is arrived at that is less than 10. Thus the digital root of 467 is 8. We shall call a Digital Root Sum (DRS) the sum of the digital roots of the individual factors of our number. The chart below demonstrates all of the DRS values for 24. FactorisationDigital Root Sum2x2x2x3 92x3x4 92x2x6 104x6 103x8 112x12 524 6The maximum Digital Root Sum of 24 is 11. The function mdrs(n) gives the maximum Digital Root Sum of n. So mdrs(24)=11. Find ∑mdrs(n) for 1 < n < 1,000,000.
|
||||
Recall that the digital root of a number, in base 10, is found by adding together the digits of that number, and repeating that process until a number arrives at less than 10. Thus the digital root of 467 is 8.
|
||||
|
||||
We shall call a Digital Root Sum (DRS) the sum of the digital roots of the individual factors of our number. The chart below demonstrates all of the DRS values for 24.
|
||||
|
||||
| Factorisation | Digital Root Sum |
|
||||
|---------------|------------------|
|
||||
| 2x2x2x3 | 9 |
|
||||
| 2x3x4 | 9 |
|
||||
| 2x2x6 | 10 |
|
||||
| 4x6 | 10 |
|
||||
| 3x8 | 11 |
|
||||
| 2x12 | 5 |
|
||||
| 24 | 6 |
|
||||
|
||||
The maximum Digital Root Sum of 24 is 11. The function $mdrs(n)$ gives the maximum Digital Root Sum of $n$. So $mdrs(24) = 11$.
|
||||
|
||||
Find $\sum{mdrs(n)}$ for $1 < n < 1,000,000$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler159()` should return 14489159.
|
||||
`euler159()` should return `14489159`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler159(), 14489159);
|
||||
|
@ -8,24 +8,24 @@ dashedName: problem-160-factorial-trailing-digits
|
||||
|
||||
# --description--
|
||||
|
||||
For any N, let f(N) be the last five digits before the trailing zeroes in N!.
|
||||
For any $N$, let $f(N)$ be the last five digits before the trailing zeroes in $N!$.
|
||||
|
||||
For example,
|
||||
|
||||
9! = 362880 so f(9)=36288
|
||||
$$\begin{align}
|
||||
& 9! = 362880 \\; \text{so} \\; f(9) = 36288 \\\\
|
||||
& 10! = 3628800 \\; \text{so} \\; f(10) = 36288 \\\\
|
||||
& 20! = 2432902008176640000 \\; \text{so} \\; f(20) = 17664
|
||||
\end{align}$$
|
||||
|
||||
10! = 3628800 so f(10)=36288
|
||||
|
||||
20! = 2432902008176640000 so f(20)=17664
|
||||
|
||||
Find f(1,000,000,000,000)
|
||||
Find $f(1,000,000,000,000)$
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler160()` should return 16576.
|
||||
`factorialTrailingDigits()` should return `16576`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler160(), 16576);
|
||||
assert.strictEqual(factorialTrailingDigits(), 16576);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +33,12 @@ assert.strictEqual(euler160(), 16576);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler160() {
|
||||
function factorialTrailingDigits() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler160();
|
||||
factorialTrailingDigits();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
Reference in New Issue
Block a user