fix(curriculum): clean-up Project Euler 101-120 (#42597)

Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>
This commit is contained in:
gikf
2021-06-30 14:25:46 +02:00
committed by GitHub
parent 25fcf835ed
commit dc168cd96d
19 changed files with 237 additions and 141 deletions

View File

@ -10,26 +10,35 @@ dashedName: problem-101-optimum-polynomial
If we are presented with the first k terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polynomial functions that can model the sequence.
As an example, let us consider the sequence of cube numbers. This is defined by the generating function, un = n3: 1, 8, 27, 64, 125, 216, ...
As an example, let us consider the sequence of cube numbers. This is defined by the generating function, $u_n = n^3: 1, 8, 27, 64, 125, 216, \ldots$
Suppose we were only given the first two terms of this sequence. Working on the principle that "simple is best" we should assume a linear relationship and predict the next term to be 15 (common difference 7). Even if we were presented with the first three terms, by the same principle of simplicity, a quadratic relationship should be assumed.
We shall define OP(k, n) to be the nth term of the optimum polynomial generating function for the first k terms of a sequence. It should be clear that OP(k, n) will accurately generate the terms of the sequence for n ≤ k, and potentially the first incorrect term (FIT) will be OP(k, k+1); in which case we shall call it a bad OP (BOP).
We shall define $OP(k, n)$ to be the $n^{th}$ term of the optimum polynomial generating function for the first k terms of a sequence. It should be clear that $OP(k, n)$ will accurately generate the terms of the sequence for $n ≤ k$, and potentially the first incorrect term (FIT) will be $OP(k, k+1)$; in which case we shall call it a bad OP (BOP).
As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for n ≥ 2, OP(1, n) = u1.
As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for $n ≥ 2, OP(1, n) = u_1$.
Hence we obtain the following OPs for the cubic sequence:
OP(1, n) = 1 1, 1, 1, 1, ... OP(2, n) = 7n6 1, 8, 15, ... OP(3, n) = 6n211n+6 1, 8, 27, 58, ... OP(4, n) = n3 1, 8, 27, 64, 125, ...
$$\begin{array}{ll}
OP(1, n) = 1 & 1, {\color{red}1}, 1, 1, \ldots \\\\
OP(2, n) = 7n6 & 1, 8, {\color{red}{15}}, \ldots \\\\
OP(3, n) = 6n^211n+6 & 1, 8, 27, {\color{red}{58}}, \ldots \\\\
OP(4, n) = n^3 & 1, 8, 27, 64, 125, \ldots
\end{array}$$
Clearly no BOPs exist for k ≥ 4. By considering the sum of FITs generated by the BOPs (indicated in red above), we obtain 1 + 15 + 58 = 74. Consider the following tenth degree polynomial generating function: un = 1 n + n2 n3 + n4 n5 + n6 n7 + n8 n9 + n10 Find the sum of FITs for the BOPs.
Clearly no BOPs exist for k ≥ 4. By considering the sum of FITs generated by the BOPs (indicated in $\color{red}{red}$ above), we obtain 1 + 15 + 58 = 74. Consider the following tenth degree polynomial generating function:
$$u_n = 1 n + n^2 n^3 + n^4 n^5 + n^6 n^7 + n^8 n^9 + n^{10}$$
Find the sum of FITs for the BOPs.
# --hints--
`euler101()` should return 37076114526.
`optimumPolynomial()` should return `37076114526`.
```js
assert.strictEqual(euler101(), 37076114526);
assert.strictEqual(optimumPolynomial(), 37076114526);
```
# --seed--
@ -37,12 +46,12 @@ assert.strictEqual(euler101(), 37076114526);
## --seed-contents--
```js
function euler101() {
function optimumPolynomial() {
return true;
}
euler101();
optimumPolynomial();
```
# --solutions--

View File

@ -8,30 +8,35 @@ dashedName: problem-103-special-subset-sums-optimum
# --description--
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
2. If B contains more elements than C then $S(B) > S(C)$.
If B contains more elements than C then S(B) > S(C).
If $S(A)$ is minimised for a given n, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.
If S(A) is minimised for a given n, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.
$$\begin{align}
& n = 1: \\{1\\} \\\\
& n = 2: \\{1, 2\\} \\\\
& n = 3: \\{2, 3, 4\\} \\\\
& n = 4: \\{3, 5, 6, 7\\} \\\\
& n = 5: \\{6, 9, 11, 12, 13\\} \\\\
\end{align}$$
n = 1: {1}n = 2: {1, 2}n = 3: {2, 3, 4}n = 4: {3, 5, 6, 7}n = 5: {6, 9, 11, 12, 13}
It seems that for a given optimum set, $A = \\{a_1, a_2, \ldots, a_n\\}$, the next optimum set is of the form $B = \\{b, a_1 + b, a_2 + b, \ldots, a_n + b\\}$, where b is the "middle" element on the previous row.
It seems that for a given optimum set, A = {a1, a2, ... , an}, the next optimum set is of the form B = {b, a1+b, a2+b, ... ,an+b}, where b is the "middle" element on the previous row.
By applying this "rule" we would expect the optimum set for $n = 6$ to be $A = \\{11, 17, 20, 22, 23, 24\\}$, with $S(A) = 117$. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for $n = 6$ is $A = \\{11, 18, 19, 20, 22, 25\\}$, with $S(A) = 115$ and corresponding set string: `111819202225`.
By applying this "rule" we would expect the optimum set for n = 6 to be A = {11, 17, 20, 22, 23, 24}, with S(A) = 117. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for n = 6 is A = {11, 18, 19, 20, 22, 25}, with S(A) = 115 and corresponding set string: 111819202225.
Given that A is an optimum special sum set for $n = 7$, find its set string.
Given that A is an optimum special sum set for n = 7, find its set string.
NOTE: This problem is related to Problem 105 and Problem 106.
**Note:** This problem is related to Problem 105 and Problem 106.
# --hints--
`euler103()` should return 20313839404245.
`optimumSpecialSumSet()` should return the string `20313839404245`.
```js
assert.strictEqual(euler103(), 20313839404245);
assert.strictEqual(optimumSpecialSumSet(), '20313839404245');
```
# --seed--
@ -39,12 +44,12 @@ assert.strictEqual(euler103(), 20313839404245);
## --seed-contents--
```js
function euler103() {
function optimumSpecialSumSet() {
return true;
}
euler103();
optimumSpecialSumSet();
```
# --solutions--

View File

@ -10,18 +10,18 @@ dashedName: problem-104-pandigital-fibonacci-ends
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.
$F_n = F_{n 1} + F_{n 2}$, where $F_1 = 1$ and $F_2 = 1$
It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.
It turns out that $F_{541}$, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1 - 9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And $F_{2749}$, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1 - 9 pandigital.
Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.
Given that $F_k$ is the first Fibonacci number for which the first nine digits AND the last nine digits are 1 - 9 pandigital, find `k`.
# --hints--
`euler104()` should return 329468.
`pandigitalFibonacciEnds()` should return `329468`.
```js
assert.strictEqual(euler104(), 329468);
assert.strictEqual(pandigitalFibonacciEnds(), 329468);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler104(), 329468);
## --seed-contents--
```js
function euler104() {
function pandigitalFibonacciEnds() {
return true;
}
euler104();
pandigitalFibonacciEnds();
```
# --solutions--

View File

@ -8,37 +8,48 @@ dashedName: problem-105-special-subset-sums-testing
# --description--
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
2. If B contains more elements than C then $S(B) > S(C)$.
If B contains more elements than C then S(B) > S(C).
For example, {81, 88, 75, 42, 87, 84, 86, 65} is not a special sum set because 65 + 87 + 88 = 75 + 81 + 84, whereas {157, 150, 164, 119, 79, 159, 161, 139, 158} satisfies both rules for all possible subset pair combinations and $S(A) = 1286$.
For example, {81, 88, 75, 42, 87, 84, 86, 65} is not a special sum set because 65 + 87 + 88 = 75 + 81 + 84, whereas {157, 150, 164, 119, 79, 159, 161, 139, 158} satisfies both rules for all possible subset pair combinations and S(A) = 1286.
Using `sets`, an array with one-hundred sets, containing seven to twelve elements (the two examples given above are the first two sets), identify all the special sum sets, $A_1, A_2, \ldots, A_k$, and find the value of $(A_1) + S(A_2) + \cdots + S(A_k)$.
Using sets.txt (right click and "Save Link/Target As..."), a 4K text file with one-hundred sets containing seven to twelve elements (the two examples given above are the first two sets in the file), identify all the special sum sets, A1, A2, ..., Ak, and find the value of S(A1) + S(A2) + ... + S(Ak).
NOTE: This problem is related to Problem 103 and Problem 106.
**Note:** This problem is related to Problem 103 and Problem 106.
# --hints--
`euler105()` should return 73702.
`testingSpecialSubsetSums(testSets)` should return `73702`.
```js
assert.strictEqual(euler105(), 73702);
assert.strictEqual(testingSpecialSubsetSums(_testSets), 73702);
```
# --seed--
## --after-user-code--
```js
const _testSets = [
[81,88,75,42,87,84,86,65],[157,150,164,119,79,159,161,139,158],[673,465,569,603,629,592,584,300,601,599,600],[90,85,83,84,65,87,76,46],[165,168,169,190,162,85,176,167,127],[224,275,278,249,277,279,289,295,139],[354,370,362,384,359,324,360,180,350,270],[599,595,557,298,448,596,577,667,597,588,602],[175,199,137,88,187,173,168,171,174],[93,187,196,144,185,178,186,202,182],[157,155,81,158,119,176,152,167,159],[184,165,159,166,163,167,174,124,83],[1211,1212,1287,605,1208,1189,1060,1216,1243,1200,908,1210],[339,299,153,305,282,304,313,306,302,228],[94,104,63,112,80,84,93,96],[41,88,82,85,61,74,83,81],[90,67,84,83,82,97,86,41],[299,303,151,301,291,302,307,377,333,280],[55,40,48,44,25,42,41],[1038,1188,1255,1184,594,890,1173,1151,1186,1203,1187,1195],[76,132,133,144,135,99,128,154],[77,46,108,81,85,84,93,83],[624,596,391,605,529,610,607,568,604,603,453],[83,167,166,189,163,174,160,165,133],[308,281,389,292,346,303,302,304,300,173],[593,1151,1187,1184,890,1040,1173,1186,1195,1255,1188,1203],[68,46,64,33,60,58,65],[65,43,88,87,86,99,93,90],[83,78,107,48,84,87,96,85],[1188,1173,1256,1038,1187,1151,890,1186,1184,1203,594,1195],[302,324,280,296,294,160,367,298,264,299],[521,760,682,687,646,664,342,698,692,686,672],[56,95,86,97,96,89,108,120],[344,356,262,343,340,382,337,175,361,330],[47,44,42,27,41,40,37],[139,155,161,158,118,166,154,156,78],[118,157,164,158,161,79,139,150,159],[299,292,371,150,300,301,281,303,306,262],[85,77,86,84,44,88,91,67],[88,85,84,44,65,91,76,86],[138,141,127,96,136,154,135,76],[292,308,302,346,300,324,304,305,238,166],[354,342,341,257,348,343,345,321,170,301],[84,178,168,167,131,170,193,166,162],[686,701,706,673,694,687,652,343,683,606,518],[295,293,301,367,296,279,297,263,323,159],[1038,1184,593,890,1188,1173,1187,1186,1195,1150,1203,1255],[343,364,388,402,191,383,382,385,288,374],[1187,1036,1183,591,1184,1175,888,1197,1182,1219,1115,1167],[151,291,307,303,345,238,299,323,301,302],[140,151,143,138,99,69,131,137],[29,44,42,59,41,36,40],[348,329,343,344,338,315,169,359,375,271],[48,39,34,37,50,40,41],[593,445,595,558,662,602,591,297,610,580,594],[686,651,681,342,541,687,691,707,604,675,699],[180,99,189,166,194,188,144,187,199],[321,349,335,343,377,176,265,356,344,332],[1151,1255,1195,1173,1184,1186,1188,1187,1203,593,1038,891],[90,88,100,83,62,113,80,89],[308,303,238,300,151,304,324,293,346,302],[59,38,50,41,42,35,40],[352,366,174,355,344,265,343,310,338,331],[91,89,93,90,117,85,60,106],[146,186,166,175,202,92,184,183,189],[82,67,96,44,80,79,88,76],[54,50,58,66,31,61,64],[343,266,344,172,308,336,364,350,359,333],[88,49,87,82,90,98,86,115],[20,47,49,51,54,48,40],[159,79,177,158,157,152,155,167,118],[1219,1183,1182,1115,1035,1186,591,1197,1167,887,1184,1175],[611,518,693,343,704,667,686,682,677,687,725],[607,599,634,305,677,604,603,580,452,605,591],[682,686,635,675,692,730,687,342,517,658,695],[662,296,573,598,592,584,553,593,595,443,591],[180,185,186,199,187,210,93,177,149],[197,136,179,185,156,182,180,178,99],[271,298,218,279,285,282,280,238,140],[1187,1151,890,593,1194,1188,1184,1173,1038,1186,1255,1203],[169,161,177,192,130,165,84,167,168],[50,42,43,41,66,39,36],[590,669,604,579,448,599,560,299,601,597,598],[174,191,206,179,184,142,177,180,90],[298,299,297,306,164,285,374,269,329,295],[181,172,162,138,170,195,86,169,168],[1184,1197,591,1182,1186,889,1167,1219,1183,1033,1115,1175],[644,695,691,679,667,687,340,681,770,686,517],[606,524,592,576,628,593,591,584,296,444,595],[94,127,154,138,135,74,136,141],[179,168,172,178,177,89,198,186,137],[302,299,291,300,298,149,260,305,280,370],[678,517,670,686,682,768,687,648,342,692,702],[302,290,304,376,333,303,306,298,279,153],[95,102,109,54,96,75,85,97],[150,154,146,78,152,151,162,173,119],[150,143,157,152,184,112,154,151,132],[36,41,54,40,25,44,42],[37,48,34,59,39,41,40],[681,603,638,611,584,303,454,607,606,605,596]
];
```
## --seed-contents--
```js
function euler105() {
function testingSpecialSubsetSums(sets) {
return true;
}
euler105();
const testSets = [
[81,88,75,42,87,84,86,65],[157,150,164,119,79,159,161,139,158],[673,465,569,603,629,592,584,300,601,599,600],[90,85,83,84,65,87,76,46],[165,168,169,190,162,85,176,167,127],[224,275,278,249,277,279,289,295,139],[354,370,362,384,359,324,360,180,350,270],[599,595,557,298,448,596,577,667,597,588,602],[175,199,137,88,187,173,168,171,174],[93,187,196,144,185,178,186,202,182],[157,155,81,158,119,176,152,167,159],[184,165,159,166,163,167,174,124,83],[1211,1212,1287,605,1208,1189,1060,1216,1243,1200,908,1210],[339,299,153,305,282,304,313,306,302,228],[94,104,63,112,80,84,93,96],[41,88,82,85,61,74,83,81],[90,67,84,83,82,97,86,41],[299,303,151,301,291,302,307,377,333,280],[55,40,48,44,25,42,41],[1038,1188,1255,1184,594,890,1173,1151,1186,1203,1187,1195],[76,132,133,144,135,99,128,154],[77,46,108,81,85,84,93,83],[624,596,391,605,529,610,607,568,604,603,453],[83,167,166,189,163,174,160,165,133],[308,281,389,292,346,303,302,304,300,173],[593,1151,1187,1184,890,1040,1173,1186,1195,1255,1188,1203],[68,46,64,33,60,58,65],[65,43,88,87,86,99,93,90],[83,78,107,48,84,87,96,85],[1188,1173,1256,1038,1187,1151,890,1186,1184,1203,594,1195],[302,324,280,296,294,160,367,298,264,299],[521,760,682,687,646,664,342,698,692,686,672],[56,95,86,97,96,89,108,120],[344,356,262,343,340,382,337,175,361,330],[47,44,42,27,41,40,37],[139,155,161,158,118,166,154,156,78],[118,157,164,158,161,79,139,150,159],[299,292,371,150,300,301,281,303,306,262],[85,77,86,84,44,88,91,67],[88,85,84,44,65,91,76,86],[138,141,127,96,136,154,135,76],[292,308,302,346,300,324,304,305,238,166],[354,342,341,257,348,343,345,321,170,301],[84,178,168,167,131,170,193,166,162],[686,701,706,673,694,687,652,343,683,606,518],[295,293,301,367,296,279,297,263,323,159],[1038,1184,593,890,1188,1173,1187,1186,1195,1150,1203,1255],[343,364,388,402,191,383,382,385,288,374],[1187,1036,1183,591,1184,1175,888,1197,1182,1219,1115,1167],[151,291,307,303,345,238,299,323,301,302],[140,151,143,138,99,69,131,137],[29,44,42,59,41,36,40],[348,329,343,344,338,315,169,359,375,271],[48,39,34,37,50,40,41],[593,445,595,558,662,602,591,297,610,580,594],[686,651,681,342,541,687,691,707,604,675,699],[180,99,189,166,194,188,144,187,199],[321,349,335,343,377,176,265,356,344,332],[1151,1255,1195,1173,1184,1186,1188,1187,1203,593,1038,891],[90,88,100,83,62,113,80,89],[308,303,238,300,151,304,324,293,346,302],[59,38,50,41,42,35,40],[352,366,174,355,344,265,343,310,338,331],[91,89,93,90,117,85,60,106],[146,186,166,175,202,92,184,183,189],[82,67,96,44,80,79,88,76],[54,50,58,66,31,61,64],[343,266,344,172,308,336,364,350,359,333],[88,49,87,82,90,98,86,115],[20,47,49,51,54,48,40],[159,79,177,158,157,152,155,167,118],[1219,1183,1182,1115,1035,1186,591,1197,1167,887,1184,1175],[611,518,693,343,704,667,686,682,677,687,725],[607,599,634,305,677,604,603,580,452,605,591],[682,686,635,675,692,730,687,342,517,658,695],[662,296,573,598,592,584,553,593,595,443,591],[180,185,186,199,187,210,93,177,149],[197,136,179,185,156,182,180,178,99],[271,298,218,279,285,282,280,238,140],[1187,1151,890,593,1194,1188,1184,1173,1038,1186,1255,1203],[169,161,177,192,130,165,84,167,168],[50,42,43,41,66,39,36],[590,669,604,579,448,599,560,299,601,597,598],[174,191,206,179,184,142,177,180,90],[298,299,297,306,164,285,374,269,329,295],[181,172,162,138,170,195,86,169,168],[1184,1197,591,1182,1186,889,1167,1219,1183,1033,1115,1175],[644,695,691,679,667,687,340,681,770,686,517],[606,524,592,576,628,593,591,584,296,444,595],[94,127,154,138,135,74,136,141],[179,168,172,178,177,89,198,186,137],[302,299,291,300,298,149,260,305,280,370],[678,517,670,686,682,768,687,648,342,692,702],[302,290,304,376,333,303,306,298,279,153],[95,102,109,54,96,75,85,97],[150,154,146,78,152,151,162,173,119],[150,143,157,152,184,112,154,151,132],[36,41,54,40,25,44,42],[37,48,34,59,39,41,40],[681,603,638,611,584,303,454,607,606,605,596]
];
testingSpecialSubsetSums(testSets);
```
# --solutions--

View File

@ -8,11 +8,10 @@ dashedName: problem-106-special-subset-sums-meta-testing
# --description--
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
Let $S(A)$ represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
If B contains more elements than C then S(B) > S(C).
1. $S(B) ≠ S(C)$; that is, sums of subsets cannot be equal.
2. If B contains more elements than C then $S(B) > S(C)$.
For this problem we shall assume that a given set contains n strictly increasing elements and it already satisfies the second rule.
@ -20,14 +19,14 @@ Surprisingly, out of the 25 possible subset pairs that can be obtained from a se
For n = 12, how many of the 261625 subset pairs that can be obtained need to be tested for equality?
NOTE: This problem is related to Problem 103 and Problem 105.
**Note:** This problem is related to Problem 103 and Problem 105.
# --hints--
`euler106()` should return 21384.
`subsetSumsMetaTesting()` should return `21384`.
```js
assert.strictEqual(euler106(), 21384);
assert.strictEqual(subsetSumsMetaTesting(), 21384);
```
# --seed--
@ -35,12 +34,12 @@ assert.strictEqual(euler106(), 21384);
## --seed-contents--
```js
function euler106() {
function subsetSumsMetaTesting() {
return true;
}
euler106();
subsetSumsMetaTesting();
```
# --solutions--

View File

@ -10,19 +10,23 @@ dashedName: problem-108-diophantine-reciprocals-i
In the following equation x, y, and n are positive integers.
1/`x` + 1/`y` = 1/`n`
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}$$
For `n` = 4 there are exactly three distinct solutions:
1/5 + 1/20 = 1/4
1/6 + 1/12 = 1/4
1/8 + 1/8 = 1/4
$$\begin{align}
& \frac{1}{5} + \frac{1}{20} = \frac{1}{4}\\\\
\\\\
& \frac{1}{6} + \frac{1}{12} = \frac{1}{4}\\\\
\\\\
& \frac{1}{8} + \frac{1}{8} = \frac{1}{4}
\end{align}$$
What is the least value of `n` for which the number of distinct solutions exceeds one-thousand?
# --hints--
`diophantineOne()` should return 180180.
`diophantineOne()` should return `180180`.
```js
assert.strictEqual(diophantineOne(), 180180);

View File

@ -10,28 +10,38 @@ dashedName: problem-109-darts
In the game of darts a player throws three darts at a target board which is split into twenty equal sized sections numbered one to twenty.
The score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively. At the centre of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points. There are many variations of rules but in the most popular game the players will begin with a score 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a "doubles out" system, which means that the player must land a double (including the double bulls-eye at the centre of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is "bust". When a player is able to finish on their current score it is called a "checkout" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull). There are exactly eleven distinct ways to checkout on a score of 6:
<img class="img-responsive center-block" alt="Darts board" src="https://cdn.freecodecamp.org/curriculum/project-euler/darts.png" style="background-color: white; padding: 10px;">
D3
The score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively.
D1 D2
At the center of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points.
S2 D2
There are many variations of rules but in the most popular game the players will begin with a score of 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a "doubles out" system, which means that the player must land a double (including the double bulls-eye at the center of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is "bust".
D2 D1
When a player is able to finish on their current score it is called a "checkout" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull). There are exactly eleven distinct ways to checkout on a score of 6:
S4 D1
$$\begin{array}
\text{D3} & & \\\\
D1 & D2 & \\\\
S2 & D2 & \\\\
D2 & D1 & \\\\
S4 & D1 & \\\\
S1 & S1 & D2 \\\\
S1 & T1 & D1 \\\\
S1 & S3 & D1 \\\\
D1 & D1 & D1 \\\\
D1 & S2 & D1 \\\\
S2 & S2 & D1
\end{array}$$
S1 S1 D2 S1 T1 D1 S1 S3 D1 D1 D1 D1 D1 S2 D1 S2 S2 D1
Note that D1 D2 is considered different to D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1. In addition we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3. Incredibly there are 42336 distinct ways of checking out in total. How many distinct ways can a player checkout with a score less than 100?
Note that D1 D2 is considered different from D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1. In addition, we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3. Incredibly there are 42336 distinct ways of checking out in total. How many distinct ways can a player checkout with a score less than 100?
# --hints--
`euler109()` should return 38182.
`darts()` should return `38182`.
```js
assert.strictEqual(euler109(), 38182);
assert.strictEqual(darts(), 38182);
```
# --seed--
@ -39,12 +49,12 @@ assert.strictEqual(euler109(), 38182);
## --seed-contents--
```js
function euler109() {
function darts() {
return true;
}
euler109();
darts();
```
# --solutions--

View File

@ -10,15 +10,17 @@ dashedName: problem-110-diophantine-reciprocals-ii
In the following equation x, y, and n are positive integers.
1/`x` + 1/`y` = 1/`n`
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}$$
It can be verified that when `n` = 1260 there are 113 distinct solutions and this is the least value of `n` for which the total number of distinct solutions exceeds one hundred.
What is the least value of `n` for which the number of distinct solutions exceeds four million?
**Note:** This problem is a much more difficult version of Problem 108 and as it is well beyond the limitations of a brute force approach it requires a clever implementation.
# --hints--
`diophantineTwo()` should return 9350130049860600.
`diophantineTwo()` should return `9350130049860600`.
```js
assert.strictEqual(diophantineTwo(), 9350130049860600);

View File

@ -10,24 +10,35 @@ dashedName: problem-111-primes-with-runs
Considering 4-digit primes containing repeated digits it is clear that they cannot all be the same: 1111 is divisible by 11, 2222 is divisible by 22, and so on. But there are nine 4-digit primes containing three ones:
1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111
$$1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111$$
We shall say that M(n, d) represents the maximum number of repeated digits for an n-digit prime where d is the repeated digit, N(n, d) represents the number of such primes, and S(n, d) represents the sum of these primes.
We shall say that $M(n, d)$ represents the maximum number of repeated digits for an n-digit prime where d is the repeated digit, $N(n, d)$ represents the number of such primes, and $S(n, d)$ represents the sum of these primes.
So M(4, 1) = 3 is the maximum number of repeated digits for a 4-digit prime where one is the repeated digit, there are N(4, 1) = 9 such primes, and the sum of these primes is S(4, 1) = 22275. It turns out that for d = 0, it is only possible to have M(4, 0) = 2 repeated digits, but there are N(4, 0) = 13 such cases.
So $M(4, 1) = 3$ is the maximum number of repeated digits for a 4-digit prime where one is the repeated digit, there are $N(4, 1) = 9$ such primes, and the sum of these primes is $S(4, 1) = 22275$. It turns out that for d = 0, it is only possible to have $M(4, 0) = 2$ repeated digits, but there are $N(4, 0) = 13$ such cases.
In the same way we obtain the following results for 4-digit primes.
Digit, d M(4, d) N(4, d) S(4, d) 0 2 13 67061 1 3 9 22275 2 3 1 2221 3 3 12 46214 4 3 2 8888 5 3 1 5557 6 3 1 6661 7 3 9 57863 8 3 1 8887 9 3 7 48073
| Digit, d | $M(4, d)$ | $N(4, d)$ | $S(4, d)$ |
|----------|-----------|-----------|-----------|
| 0 | 2 | 13 | 67061 |
| 1 | 3 | 9 | 22275 |
| 2 | 3 | 1 | 2221 |
| 3 | 3 | 12 | 46214 |
| 4 | 3 | 2 | 8888 |
| 5 | 3 | 1 | 5557 |
| 6 | 3 | 1 | 6661 |
| 7 | 3 | 9 | 57863 |
| 8 | 3 | 1 | 8887 |
| 9 | 3 | 7 | 48073 |
For d = 0 to 9, the sum of all S(4, d) is 273700. Find the sum of all S(10, d).
For d = 0 to 9, the sum of all $S(4, d)$ is 273700. Find the sum of all $S(10, d)$.
# --hints--
`euler111()` should return 612407567715.
`primesWithRuns()` should return `612407567715`.
```js
assert.strictEqual(euler111(), 612407567715);
assert.strictEqual(primesWithRuns(), 612407567715);
```
# --seed--
@ -35,12 +46,12 @@ assert.strictEqual(euler111(), 612407567715);
## --seed-contents--
```js
function euler111() {
function primesWithRuns() {
return true;
}
euler111();
primesWithRuns();
```
# --solutions--

View File

@ -22,10 +22,10 @@ Find the least number for which the proportion of bouncy numbers is exactly 99%.
# --hints--
`euler112()` should return 1587000.
`bouncyNumbers()` should return `1587000`.
```js
assert.strictEqual(euler112(), 1587000);
assert.strictEqual(bouncyNumbers(), 1587000);
```
# --seed--
@ -33,12 +33,12 @@ assert.strictEqual(euler112(), 1587000);
## --seed-contents--
```js
function euler112() {
function bouncyNumbers() {
return true;
}
euler112();
bouncyNumbers();
```
# --solutions--

View File

@ -14,16 +14,16 @@ Similarly if no digit is exceeded by the digit to its right it is called a decre
We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, 155349.
As n increases, the proportion of bouncy numbers below n increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below 1010.
As n increases, the proportion of bouncy numbers below n increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below ${10}^{10}$.
How many numbers below a googol (10100) are not bouncy?
How many numbers below a googol (${10}^{100}$) are not bouncy?
# --hints--
`euler113()` should return 51161058134250.
`nonBouncyNumbers()` should return `51161058134250`.
```js
assert.strictEqual(euler113(), 51161058134250);
assert.strictEqual(nonBouncyNumbers(), 51161058134250);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler113(), 51161058134250);
## --seed-contents--
```js
function euler113() {
function nonBouncyNumbers() {
return true;
}
euler113();
nonBouncyNumbers();
```
# --solutions--

View File

@ -10,14 +10,18 @@ dashedName: problem-114-counting-block-combinations-i
A row measuring seven units in length has red blocks with a minimum length of three units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square. There are exactly seventeen ways of doing this.
How many ways can a row measuring fifty units in length be filled? NOTE: Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), black (1), and red (4).
<img class="img-responsive center-block" alt="Possible ways of placing block with a minimum length of three units, on a row with length of seven units" src="https://cdn.freecodecamp.org/curriculum/project-euler/counting-block-combinations-i.png" style="background-color: white; padding: 10px;">
How many ways can a row measuring fifty units in length be filled?
**Note:** Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), black (1), and red (4).
# --hints--
`euler114()` should return 16475640049.
`countingBlockOne()` should return `16475640049`.
```js
assert.strictEqual(euler114(), 16475640049);
assert.strictEqual(countingBlockOne(), 16475640049);
```
# --seed--
@ -25,12 +29,12 @@ assert.strictEqual(euler114(), 16475640049);
## --seed-contents--
```js
function euler114() {
function countingBlockOne() {
return true;
}
euler114();
countingBlockOne();
```
# --solutions--

View File

@ -8,26 +8,26 @@ dashedName: problem-115-counting-block-combinations-ii
# --description--
NOTE: This is a more difficult version of Problem 114.
A row measuring `n` units in length has red blocks with a minimum length of `m` units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.
A row measuring n units in length has red blocks with a minimum length of m units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.
Let the fill-count function, $F(m, n)$, represent the number of ways that a row can be filled.
Let the fill-count function, F(m, n), represent the number of ways that a row can be filled.
For example, F(3, 29) = 673135 and F(3, 30) = 1089155.
For example, $F(3, 29) = 673135$ and $F(3, 30) = 1089155$.
That is, for m = 3, it can be seen that n = 30 is the smallest value for which the fill-count function first exceeds one million.
In the same way, for m = 10, it can be verified that F(10, 56) = 880711 and F(10, 57) = 1148904, so n = 57 is the least value for which the fill-count function first exceeds one million.
In the same way, for m = 10, it can be verified that $F(10, 56) = 880711$ and $F(10, 57) = 1148904$, so n = 57 is the least value for which the fill-count function first exceeds one million.
For m = 50, find the least value of n for which the fill-count function first exceeds one million.
For m = 50, find the least value of `n` for which the fill-count function first exceeds one million.
**Note:** This is a more difficult version of Problem 114.
# --hints--
`euler115()` should return 168.
`countingBlockTwo()` should return `168`.
```js
assert.strictEqual(euler115(), 168);
assert.strictEqual(countingBlockTwo(), 168);
```
# --seed--
@ -35,12 +35,12 @@ assert.strictEqual(euler115(), 168);
## --seed-contents--
```js
function euler115() {
function countingBlockTwo() {
return true;
}
euler115();
countingBlockTwo();
```
# --solutions--

View File

@ -12,18 +12,26 @@ A row of five black square tiles is to have a number of its tiles replaced with
If red tiles are chosen there are exactly seven ways this can be done.
<img class="img-responsive center-block" alt="Possible ways to placing red oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-1.png" style="background-color: white; padding: 10px;">
If green tiles are chosen there are three ways.
<img class="img-responsive center-block" alt="Possible ways of placing green oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-2.png" style="background-color: white; padding: 10px;">
And if blue tiles are chosen there are two ways.
Assuming that colours cannot be mixed there are 7 + 3 + 2 = 12 ways of replacing the black tiles in a row measuring five units in length. How many different ways can the black tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used? NOTE: This is related to Problem 117.
<img class="img-responsive center-block" alt="Possible ways of placing blue oblong on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-or-blue-tiles-3.png" style="background-color: white; padding: 10px;">
Assuming that colors cannot be mixed there are 7 + 3 + 2 = 12 ways of replacing the black tiles in a row measuring five units in length. How many different ways can the black tiles in a row measuring fifty units in length be replaced if colors cannot be mixed and at least one colored tile must be used?
**Note:** This is related to Problem 117.
# --hints--
`euler116()` should return 20492570929.
`redGreenBlueOne()` should return `20492570929`.
```js
assert.strictEqual(euler116(), 20492570929);
assert.strictEqual(redGreenBlueOne(), 20492570929);
```
# --seed--
@ -31,12 +39,12 @@ assert.strictEqual(euler116(), 20492570929);
## --seed-contents--
```js
function euler116() {
function redGreenBlueOne() {
return true;
}
euler116();
redGreenBlueOne();
```
# --solutions--

View File

@ -10,14 +10,18 @@ dashedName: problem-117-red-green-and-blue-tiles
Using a combination of black square tiles and oblong tiles chosen from: red tiles measuring two units, green tiles measuring three units, and blue tiles measuring four units, it is possible to tile a row measuring five units in length in exactly fifteen different ways.
How many ways can a row measuring fifty units in length be tiled? NOTE: This is related to Problem 116.
<img class="img-responsive center-block" alt="Possible ways of placing red, green and blue oblongs on a row with length of five units" src="https://cdn.freecodecamp.org/curriculum/project-euler/red-green-and-blue-tiles.png" style="background-color: white; padding: 10px;">
How many ways can a row measuring fifty units in length be tiled?
**Note**: This is related to Problem 116.
# --hints--
`euler117()` should return 100808458960497.
`redGreenBlueTilesTwo()` should return `100808458960497`.
```js
assert.strictEqual(euler117(), 100808458960497);
assert.strictEqual(redGreenBlueTilesTwo(), 100808458960497);
```
# --seed--
@ -25,12 +29,12 @@ assert.strictEqual(euler117(), 100808458960497);
## --seed-contents--
```js
function euler117() {
function redGreenBlueTilesTwo() {
return true;
}
euler117();
redGreenBlueTilesTwo();
```
# --solutions--

View File

@ -8,16 +8,16 @@ dashedName: problem-118-pandigital-prime-sets
# --description--
Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set {2,5,47,89,631}, all of the elements belonging to it are prime.
Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set $\\{2, 5, 47, 89, 631\\}$, all of the elements belonging to it are prime.
How many distinct sets containing each of the digits one through nine exactly once contain only prime elements?
# --hints--
`euler118()` should return 44680.
`pandigitalPrimeSets()` should return `44680`.
```js
assert.strictEqual(euler118(), 44680);
assert.strictEqual(pandigitalPrimeSets(), 44680);
```
# --seed--
@ -25,12 +25,12 @@ assert.strictEqual(euler118(), 44680);
## --seed-contents--
```js
function euler118() {
function pandigitalPrimeSets() {
return true;
}
euler118();
pandigitalPrimeSets();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-119-digit-power-sum
# --description--
The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
The number 512 is interesting because it is equal to the sum of its digits raised to some power: $5 + 1 + 2 = 8$, and $8^3 = 512$. Another example of a number with this property is $614656 = 28^4$.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
We shall define an to be the $n-th$ term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
You are given that $a_2 = 512$ and $a_{10} = 614656$.
Find a30.
Find $a_{30}$.
# --hints--
`euler119()` should return 248155780267521.
`digitPowerSum()` should return `248155780267521`.
```js
assert.strictEqual(euler119(), 248155780267521);
assert.strictEqual(digitPowerSum(), 248155780267521);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler119(), 248155780267521);
## --seed-contents--
```js
function euler119() {
function digitPowerSum() {
return true;
}
euler119();
digitPowerSum();
```
# --solutions--

View File

@ -8,18 +8,18 @@ dashedName: problem-120-square-remainders
# --description--
Let r be the remainder when (a1)n + (a+1)n is divided by a2.
Let `r` be the remainder when ${(a 1)}^n + {(a + 1)}^n$ is divided by $a^2$.
For example, if a = 7 and n = 3, then r = 42: 63 + 83 = 728 ≡ 42 mod 49. And as n varies, so too will r, but for a = 7 it turns out that rmax = 42.
For example, if $a = 7$ and $n = 3$, then $r = 42: 6^3 + 8^3 = 728 ≡ 42 \\ \text{mod}\\ 49$. And as `n` varies, so too will `r`, but for $a = 7$ it turns out that $r_{max} = 42$.
For 3 ≤ a ≤ 1000, find ∑ rmax.
For $3 ≤ a ≤ 1000$, find $\sum{r}_{max}$.
# --hints--
`euler120()` should return 333082500.
`squareRemainders()` should return `333082500`.
```js
assert.strictEqual(euler120(), 333082500);
assert.strictEqual(squareRemainders(), 333082500);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler120(), 333082500);
## --seed-contents--
```js
function euler120() {
function squareRemainders() {
return true;
}
euler120();
squareRemainders();
```
# --solutions--