fix(curriculum): clean-up Project Euler 201-220 (#42826)

* fix: clean-up Project Euler 201-220

* fix: corrections from review

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
gikf
2021-07-15 09:20:31 +02:00
committed by GitHub
parent 505c3b7c6c
commit eef1805fe6
20 changed files with 254 additions and 156 deletions

View File

@ -8,24 +8,45 @@ dashedName: problem-201-subsets-with-a-unique-sum
# --description--
For any set A of numbers, let sum(A) be the sum of the elements of A.
For any set $A$ of numbers, let $sum(A)$ be the sum of the elements of $A$.
Consider the set B = {1,3,6,8,10,11}. There are 20 subsets of B containing three elements, and their sums are:
Consider the set $B = \\{1,3,6,8,10,11\\}$. There are 20 subsets of $B$ containing three elements, and their sums are:
sum({1,3,6}) = 10, sum({1,3,8}) = 12, sum({1,3,10}) = 14, sum({1,3,11}) = 15, sum({1,6,8}) = 15, sum({1,6,10}) = 17, sum({1,6,11}) = 18, sum({1,8,10}) = 19, sum({1,8,11}) = 20, sum({1,10,11}) = 22, sum({3,6,8}) = 17, sum({3,6,10}) = 19, sum({3,6,11}) = 20, sum({3,8,10}) = 21, sum({3,8,11}) = 22, sum({3,10,11}) = 24, sum({6,8,10}) = 24, sum({6,8,11}) = 25, sum({6,10,11}) = 27, sum({8,10,11}) = 29.
$$\begin{align}
& sum(\\{1,3,6\\}) = 10 \\\\
& sum(\\{1,3,8\\}) = 12 \\\\
& sum(\\{1,3,10\\}) = 14 \\\\
& sum(\\{1,3,11\\}) = 15 \\\\
& sum(\\{1,6,8\\}) = 15 \\\\
& sum(\\{1,6,10\\}) = 17 \\\\
& sum(\\{1,6,11\\}) = 18 \\\\
& sum(\\{1,8,10\\}) = 19 \\\\
& sum(\\{1,8,11\\}) = 20 \\\\
& sum(\\{1,10,11\\}) = 22 \\\\
& sum(\\{3,6,8\\}) = 17 \\\\
& sum(\\{3,6,10\\}) = 19 \\\\
& sum(\\{3,6,11\\}) = 20 \\\\
& sum(\\{3,8,10\\}) = 21 \\\\
& sum(\\{3,8,11\\}) = 22 \\\\
& sum(\\{3,10,11\\}) = 24 \\\\
& sum(\\{6,8,10\\}) = 24 \\\\
& sum(\\{6,8,11\\}) = 25 \\\\
& sum(\\{6,10,11\\}) = 27 \\\\
& sum(\\{8,10,11\\}) = 29
\\end{align}$$
Some of these sums occur more than once, others are unique. For a set A, let U(A,k) be the set of unique sums of k-element subsets of A, in our example we find U(B,3) = {10,12,14,18,21,25,27,29} and sum(U(B,3)) = 156.
Some of these sums occur more than once, others are unique. For a set $A$, let $U(A,k)$ be the set of unique sums of $k$-element subsets of $A$, in our example we find $U(B,3) = \\{10,12,14,18,21,25,27,29\\}$ and $sum(U(B,3)) = 156$.
Now consider the 100-element set S = {12, 22, ... , 1002}. S has 100891344545564193334812497256 50-element subsets.
Now consider the $100$-element set $S = \\{1^2, 2^2, \ldots , {100}^2\\}$. $S$ has $100\\,891\\,344\\,545\\,564\\,193\\,334\\,812\\,497\\,256\\;$ $50$-element subsets.
Determine the sum of all integers which are the sum of exactly one of the 50-element subsets of S, i.e. find sum(U(S,50)).
Determine the sum of all integers which are the sum of exactly one of the $50$-element subsets of $S$, i.e. find $sum(U(S,50))$.
# --hints--
`euler201()` should return 115039000.
`uniqueSubsetsSum()` should return `115039000`.
```js
assert.strictEqual(euler201(), 115039000);
assert.strictEqual(uniqueSubsetsSum(), 115039000);
```
# --seed--
@ -33,12 +54,12 @@ assert.strictEqual(euler201(), 115039000);
## --seed-contents--
```js
function euler201() {
function uniqueSubsetsSum() {
return true;
}
euler201();
uniqueSubsetsSum();
```
# --solutions--

View File

@ -10,18 +10,20 @@ dashedName: problem-202-laserbeam
Three mirrors are arranged in the shape of an equilateral triangle, with their reflective surfaces pointing inwards. There is an infinitesimal gap at each vertex of the triangle through which a laser beam may pass.
Label the vertices A, B and C. There are 2 ways in which a laser beam may enter vertex C, bounce off 11 surfaces, then exit through the same vertex: one way is shown below; the other is the reverse of that.
Label the vertices $A$, $B$ and $C$. There are 2 ways in which a laser beam may enter vertex $C$, bounce off 11 surfaces, then exit through the same vertex: one way is shown below; the other is the reverse of that.
There are 80840 ways in which a laser beam may enter vertex C, bounce off 1000001 surfaces, then exit through the same vertex.
<img class="img-responsive center-block" alt="one way in which laser beam may enter vertex C, bounce off 11 surfaces and exit through the same vertex" src="https://cdn.freecodecamp.org/curriculum/project-euler/laserbeam.gif" style="background-color: white; padding: 10px;">
In how many ways can a laser beam enter at vertex C, bounce off 12017639147 surfaces, then exit through the same vertex?
There are 80840 ways in which a laser beam may enter vertex $C$, bounce off 1000001 surfaces, then exit through the same vertex.
In how many ways can a laser beam enter at vertex $C$, bounce off 12017639147 surfaces, then exit through the same vertex?
# --hints--
`euler202()` should return 1209002624.
`laserbeam()` should return `1209002624`.
```js
assert.strictEqual(euler202(), 1209002624);
assert.strictEqual(laserbeam(), 1209002624);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler202(), 1209002624);
## --seed-contents--
```js
function euler202() {
function laserbeam() {
return true;
}
euler202();
laserbeam();
```
# --solutions--

View File

@ -8,9 +8,19 @@ dashedName: problem-203-squarefree-binomial-coefficients
# --description--
The binomial coefficients nCk can be arranged in triangular form, Pascal's triangle, like this:
The binomial coefficients $\displaystyle\binom{n}{k}$ can be arranged in triangular form, Pascal's triangle, like this:
111121133114641151010511615201561172135352171 .........
$$\begin{array}{ccccccccccccccc}
& & & & & & & 1 & & & & & & & \\\\
& & & & & & 1 & & 1 & & & & & & \\\\
& & & & & 1 & & 2 & & 1 & & & & & \\\\
& & & & 1 & & 3 & & 3 & & 1 & & & & \\\\
& & & 1 & & 4 & & 6 & & 4 & & 1 & & & \\\\
& & 1 & & 5 & & 10 & & 10 & & 5 & & 1 & & \\\\
& 1 & & 6 & & 15 & & 20 & & 15 & & 6 & & 1 & \\\\
1 & & 7 & & 21 & & 35 & & 35 & & 21 & & 7 & & 1 \\\\
& & & & & & & \ldots
\end{array}$$
It can be seen that the first eight rows of Pascal's triangle contain twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 21 and 35.
@ -20,10 +30,10 @@ Find the sum of the distinct squarefree numbers in the first 51 rows of Pascal's
# --hints--
`euler203()` should return 34029210557338.
`squarefreeBinomialCoefficients()` should return `34029210557338`.
```js
assert.strictEqual(euler203(), 34029210557338);
assert.strictEqual(squarefreeBinomialCoefficients(), 34029210557338);
```
# --seed--
@ -31,12 +41,12 @@ assert.strictEqual(euler203(), 34029210557338);
## --seed-contents--
```js
function euler203() {
function squarefreeBinomialCoefficients() {
return true;
}
euler203();
squarefreeBinomialCoefficients();
```
# --solutions--

View File

@ -12,18 +12,18 @@ A Hamming number is a positive number which has no prime factor larger than 5.
So the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.
There are 1105 Hamming numbers not exceeding 108.
There are 1105 Hamming numbers not exceeding ${10}^8$.
We will call a positive number a generalised Hamming number of type n, if it has no prime factor larger than n. Hence the Hamming numbers are the generalised Hamming numbers of type 5.
We will call a positive number a generalised Hamming number of type $n$, if it has no prime factor larger than $n$. Hence the Hamming numbers are the generalised Hamming numbers of type 5.
How many generalised Hamming numbers of type 100 are there which don't exceed 109?
How many generalised Hamming numbers of type 100 are there which don't exceed ${10}^9$?
# --hints--
`euler204()` should return 2944730.
`generalisedHammingNumbers()` should return `2944730`.
```js
assert.strictEqual(euler204(), 2944730);
assert.strictEqual(generalisedHammingNumbers(), 2944730);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler204(), 2944730);
## --seed-contents--
```js
function euler204() {
function generalisedHammingNumbers() {
return true;
}
euler204();
generalisedHammingNumbers();
```
# --solutions--

View File

@ -18,10 +18,10 @@ What is the probability that Pyramidal Pete beats Cubic Colin? Give your answer
# --hints--
`euler205()` should return 0.5731441.
`diceGame()` should return `0.5731441`.
```js
assert.strictEqual(euler205(), 0.5731441);
assert.strictEqual(diceGame(), 0.5731441);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler205(), 0.5731441);
## --seed-contents--
```js
function euler205() {
function diceGame() {
return true;
}
euler205();
diceGame();
```
# --solutions--

View File

@ -8,14 +8,14 @@ dashedName: problem-206-concealed-square
# --description--
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0, where each “\_” is a single digit.
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0, where each "_" is a single digit.
# --hints--
`euler206()` should return 1389019170.
`concealedSquare()` should return `1389019170`.
```js
assert.strictEqual(euler206(), 1389019170);
assert.strictEqual(concealedSquare(), 1389019170);
```
# --seed--
@ -23,12 +23,12 @@ assert.strictEqual(euler206(), 1389019170);
## --seed-contents--
```js
function euler206() {
function concealedSquare() {
return true;
}
euler206();
concealedSquare();
```
# --solutions--

View File

@ -8,24 +8,38 @@ dashedName: problem-207-integer-partition-equations
# --description--
For some positive integers k, there exists an integer partition of the form 4t = 2t + k,
For some positive integers $k$, there exists an integer partition of the form $4^t = 2^t + k$,
where 4t, 2t, and k are all positive integers and t is a real number.
where $4^t$, $2^t$, and $k$ are all positive integers and $t$ is a real number.
The first two such partitions are 41 = 21 + 2 and 41.5849625... = 21.5849625... + 6.
The first two such partitions are $4^1 = 2^1 + 2$ and $4^{1.584\\,962\\,5\ldots} = 2^{1.584\\,962\\,5\ldots} + 6$.
Partitions where t is also an integer are called perfect. For any m ≥ 1 let P(m) be the proportion of such partitions that are perfect with k ≤ m. Thus P(6) = 1/2.
Partitions where $t$ is also an integer are called perfect. For any $m ≥ 1$ let $P(m)$ be the proportion of such partitions that are perfect with $k ≤ m$.
In the following table are listed some values of P(m) P(5) = 1/1 P(10) = 1/2 P(15) = 2/3 P(20) = 1/2 P(25) = 1/2 P(30) = 2/5 ... P(180) = 1/4 P(185) = 3/13
Thus $P(6) = \frac{1}{2}$.
Find the smallest m for which P(m) &lt; 1/12345
In the following table are listed some values of $P(m)$
$$\begin{align}
& P(5) = \frac{1}{1} \\\\
& P(10) = \frac{1}{2} \\\\
& P(15) = \frac{2}{3} \\\\
& P(20) = \frac{1}{2} \\\\
& P(25) = \frac{1}{2} \\\\
& P(30) = \frac{2}{5} \\\\
& \ldots \\\\
& P(180) = \frac{1}{4} \\\\
& P(185) = \frac{3}{13}
\end{align}$$
Find the smallest $m$ for which $P(m) &lt; \frac{1}{12\\,345}$
# --hints--
`euler207()` should return 44043947822.
`integerPartitionEquations()` should return `44043947822`.
```js
assert.strictEqual(euler207(), 44043947822);
assert.strictEqual(integerPartitionEquations(), 44043947822);
```
# --seed--
@ -33,12 +47,12 @@ assert.strictEqual(euler207(), 44043947822);
## --seed-contents--
```js
function euler207() {
function integerPartitionEquations() {
return true;
}
euler207();
integerPartitionEquations();
```
# --solutions--

View File

@ -12,14 +12,18 @@ A robot moves in a series of one-fifth circular arcs (72°), with a free choice
One of 70932 possible closed paths of 25 arcs starting northward is
Given that the robot starts facing North, how many journeys of 70 arcs in length can it take that return it, after the final arc, to its starting position? (Any arc may be traversed multiple times.)
<img class="img-responsive center-block" alt="closed path of 25 arcs, starting northward" src="https://cdn.freecodecamp.org/curriculum/project-euler/robot-walks.gif" style="background-color: white; padding: 10px;">
Given that the robot starts facing North, how many journeys of 70 arcs in length can it take that return it, after the final arc, to its starting position?
**Note:** Any arc may be traversed multiple times.
# --hints--
`euler208()` should return 331951449665644800.
`robotWalks()` should return `331951449665644800`.
```js
assert.strictEqual(euler208(), 331951449665644800);
assert.strictEqual(robotWalks(), 331951449665644800);
```
# --seed--
@ -27,12 +31,12 @@ assert.strictEqual(euler208(), 331951449665644800);
## --seed-contents--
```js
function euler208() {
function robotWalks() {
return true;
}
euler208();
robotWalks();
```
# --solutions--

View File

@ -8,20 +8,34 @@ dashedName: problem-209-circular-logic
# --description--
A k-input binary truth table is a map from k input bits
A $k$-input binary truth table is a map from $k$ input bits (binary digits, 0 [false] or 1 [true]) to 1 output bit. For example, the $2$-input binary truth tables for the logical $AND$ and $XOR$ functions are:
(binary digits, 0 \[false] or 1 \[true]) to 1 output bit. For example, the 2-input binary truth tables for the logical AND and XOR functions are:
| x | y | x AND y |
|---|---|---------|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
x y x AND y000010100111x y x XOR y000011101110How many 6-input binary truth tables, τ, satisfy the formula
| x | y | x XOR y |
|---|---|---------|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
τ(a, b, c, d, e, f) AND τ(b, c, d, e, f, a XOR (b AND c)) = 0 for all 6-bit inputs (a, b, c, d, e, f)?
How many $6$-input binary truth tables, $τ$, satisfy the formula
$$τ(a, b, c, d, e, f) \\; AND \\; τ(b, c, d, e, f, a \\; XOR \\; (b \\; AND \\; c)) = 0$$
for all $6$-bit inputs ($a$, $b$, $c$, $d$, $e$, $f$)?
# --hints--
`euler209()` should return 15964587728784.
`circularLogic()` should return `15964587728784`.
```js
assert.strictEqual(euler209(), 15964587728784);
assert.strictEqual(circularLogic(), 15964587728784);
```
# --seed--
@ -29,12 +43,12 @@ assert.strictEqual(euler209(), 15964587728784);
## --seed-contents--
```js
function euler209() {
function circularLogic() {
return true;
}
euler209();
circularLogic();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-210-obtuse-angled-triangles
# --description--
Consider the set S(r) of points (x,y) with integer coordinates satisfying |x| + |y| ≤ r.
Consider the set $S(r)$ of points ($x$,$y$) with integer coordinates satisfying $|x| + |y| ≤ r$.
Let O be the point (0,0) and C the point (r/4,r/4).
Let $O$ be the point (0,0) and $C$ the point ($\frac{r}{4}$,$\frac{r}{4}$).
Let N(r) be the number of points B in S(r), so that the triangle OBC has an obtuse angle, i.e. the largest angle α satisfies 90°&lt;α&lt;180°.
Let $N(r)$ be the number of points $B$ in $S(r)$, so that the triangle $OBC$ has an obtuse angle, i.e. the largest angle $α$ satisfies $90°&lt;α&lt;180°$.
So, for example, N(4)=24 and N(8)=100.
So, for example, $N(4)=24$ and $N(8)=100$.
What is N(1,000,000,000)?
What is $N(1\\,000\\,000\\,000)$?
# --hints--
`euler210()` should return 1598174770174689500.
`obtuseAngledTriangles()` should return `1598174770174689500`.
```js
assert.strictEqual(euler210(), 1598174770174689500);
assert.strictEqual(obtuseAngledTriangles(), 1598174770174689500);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler210(), 1598174770174689500);
## --seed-contents--
```js
function euler210() {
function obtuseAngledTriangles() {
return true;
}
euler210();
obtuseAngledTriangles();
```
# --solutions--

View File

@ -8,18 +8,18 @@ dashedName: problem-211-divisor-square-sum
# --description--
For a positive integer n, let σ2(n) be the sum of the squares of its divisors. For example,
For a positive integer $n$, let $σ_2(n)$ be the sum of the squares of its divisors. For example,
σ2(10) = 1 + 4 + 25 + 100 = 130.
$$σ_2(10) = 1 + 4 + 25 + 100 = 130$$
Find the sum of all n, 0 &lt; n &lt; 64,000,000 such that σ2(n) is a perfect square.
Find the sum of all $n$, $0 &lt; n &lt; 64\\,000\\,000$ such that $σ_2(n)$ is a perfect square.
# --hints--
`euler211()` should return 1922364685.
`divisorSquareSum()` should return `1922364685`.
```js
assert.strictEqual(euler211(), 1922364685);
assert.strictEqual(divisorSquareSum(), 1922364685);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler211(), 1922364685);
## --seed-contents--
```js
function euler211() {
function divisorSquareSum() {
return true;
}
euler211();
divisorSquareSum();
```
# --solutions--

View File

@ -8,28 +8,37 @@ dashedName: problem-212-combined-volume-of-cuboids
# --description--
An axis-aligned cuboid, specified by parameters { (x0,y0,z0), (dx,dy,dz) }, consists of all points (X,Y,Z) such that x0 ≤ X ≤ x0+dx, y0 ≤ Y ≤ y0+dy and z0 ≤ Z ≤ z0+dz. The volume of the cuboid is the product, dx × dy × dz. The combined volume of a collection of cuboids is the volume of their union and will be less than the sum of the individual volumes if any cuboids overlap.
An axis-aligned cuboid, specified by parameters $\{ (x_0,y_0,z_0), (dx,dy,dz) \}$, consists of all points ($X$,$Y$,$Z$) such that $x_0 ≤ X ≤ x_0 + dx$, $y_0 ≤ Y ≤ y_0 + dy$ and $z_0 ≤ Z ≤ z_0 + dz$. The volume of the cuboid is the product, $dx × dy × dz$. The combined volume of a collection of cuboids is the volume of their union and will be less than the sum of the individual volumes if any cuboids overlap.
Let C1,...,C50000 be a collection of 50000 axis-aligned cuboids such that Cn has parameters
Let $C_1, \ldots, C_{50000}$ be a collection of 50000 axis-aligned cuboids such that $C_n$ has parameters
x0 = S6n-5 modulo 10000y0 = S6n-4 modulo 10000z0 = S6n-3 modulo 10000dx = 1 + (S6n-2 modulo 399)dy = 1 + (S6n-1 modulo 399)dz = 1 + (S6n modulo 399)
$$\begin{align}
& x_0 = S_{6n - 5} \\; \text{modulo} \\; 10000 \\\\
& y_0 = S_{6n - 4} \\; \text{modulo} \\; 10000 \\\\
& z_0 = S_{6n - 3} \\; \text{modulo} \\; 10000 \\\\
& dx = 1 + (S_{6n - 2} \\; \text{modulo} \\; 399) \\\\
& dy = 1 + (S_{6n - 1} \\; \text{modulo} \\; 399) \\\\
& dz = 1 + (S_{6n} \\; \text{modulo} \\; 399) \\\\
\end{align}$$
where S1,...,S300000 come from the "Lagged Fibonacci Generator":
where $S_1, \ldots, S_{300000}$ come from the "Lagged Fibonacci Generator":
For 1 ≤ k ≤ 55, Sk = \[100003 - 200003k + 300007k3] (modulo 1000000)For 56 ≤ k, Sk = \[Sk-24 + Sk-55] (modulo 1000000)
For $1 ≤ k ≤ 55$, $S_k = [100003 - 200003k + 300007k^3] \\; (modulo \\; 1000000)$
Thus, C1 has parameters {(7,53,183),(94,369,56)}, C2 has parameters {(2383,3563,5079),(42,212,344)}, and so on.
For $56 ≤ k$, $S_k = [S_{k - 24} + S_{k - 55}] \\; (modulo \\; 1000000)$
The combined volume of the first 100 cuboids, C1,...,C100, is 723581599.
Thus, $C_1$ has parameters $\{(7,53,183), (94,369,56)\}$, $C_2$ has parameters $\{(2383,3563,5079), (42,212,344)\}$, and so on.
What is the combined volume of all 50000 cuboids, C1,...,C50000 ?
The combined volume of the first 100 cuboids, $C_1, \ldots, C_{100}$, is 723581599.
What is the combined volume of all 50000 cuboids, $C_1, \ldots, C_{50000}$?
# --hints--
`euler212()` should return 328968937309.
`combinedValueOfCuboids()` should return `328968937309`.
```js
assert.strictEqual(euler212(), 328968937309);
assert.strictEqual(combinedValueOfCuboids(), 328968937309);
```
# --seed--
@ -37,12 +46,12 @@ assert.strictEqual(euler212(), 328968937309);
## --seed-contents--
```js
function euler212() {
function combinedValueOfCuboids() {
return true;
}
euler212();
combinedValueOfCuboids();
```
# --solutions--

View File

@ -16,10 +16,10 @@ What is the expected number of unoccupied squares after 50 rings of the bell? Gi
# --hints--
`euler213()` should return 330.721154.
`fleaCircus()` should return `330.721154`.
```js
assert.strictEqual(euler213(), 330.721154);
assert.strictEqual(fleaCircus(), 330.721154);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler213(), 330.721154);
## --seed-contents--
```js
function euler213() {
function fleaCircus() {
return true;
}
euler213();
fleaCircus();
```
# --solutions--

View File

@ -8,24 +8,31 @@ dashedName: problem-214-totient-chains
# --description--
Let φ be Euler's totient function, i.e. for a natural number n,
Let $φ$ be Euler's totient function, i.e. for a natural number $n$, $φ(n)$ is the number of $k$, $1 ≤ k ≤ n$, for which $gcd(k,n) = 1$.
φ(n) is the number of k, 1 ≤ k ≤ n, for which gcd(k,n) = 1.
By iterating $φ$, each positive integer generates a decreasing chain of numbers ending in 1. E.g. if we start with 5 the sequence 5,4,2,1 is generated. Here is a listing of all chains with length 4:
By iterating φ, each positive integer generates a decreasing chain of numbers ending in 1. E.g. if we start with 5 the sequence 5,4,2,1 is generated. Here is a listing of all chains with length 4:
5,4,2,1 7,6,2,1 8,4,2,1 9,6,2,1 10,4,2,1 12,4,2,1 14,6,2,1 18,6,2,1
$$\begin{align}
5,4,2,1 & \\\\
7,6,2,1 & \\\\
8,4,2,1 & \\\\
9,6,2,1 & \\\\
10,4,2,1 & \\\\
12,4,2,1 & \\\\
14,6,2,1 & \\\\
18,6,2,1 &
\end{align}$$
Only two of these chains start with a prime, their sum is 12.
What is the sum of all primes less than 40000000 which generate a chain of length 25?
What is the sum of all primes less than $40\\,000\\,000$ which generate a chain of length 25?
# --hints--
`euler214()` should return 1677366278943.
`totientChains()` should return `1677366278943`.
```js
assert.strictEqual(euler214(), 1677366278943);
assert.strictEqual(totientChains(), 1677366278943);
```
# --seed--
@ -33,12 +40,12 @@ assert.strictEqual(euler214(), 1677366278943);
## --seed-contents--
```js
function euler214() {
function totientChains() {
return true;
}
euler214();
totientChains();
```
# --solutions--

View File

@ -12,16 +12,18 @@ Consider the problem of building a wall out of 2×1 and 3×1 bricks (horizontal
For example, the following 9×3 wall is not acceptable due to the running crack shown in red:
There are eight ways of forming a crack-free 9×3 wall, written W(9,3) = 8.
<img class="img-responsive center-block" alt="9x3 wall with one lined up gap between horizontally-adjacent bricks" src="https://cdn.freecodecamp.org/curriculum/project-euler/crack-free-walls.gif" style="background-color: white; padding: 10px;">
Calculate W(32,10).
There are eight ways of forming a crack-free 9×3 wall, written $W(9,3) = 8$.
Calculate $W(32,10)$.
# --hints--
`euler215()` should return 806844323190414.
`crackFreeWalls()` should return `806844323190414`.
```js
assert.strictEqual(euler215(), 806844323190414);
assert.strictEqual(crackFreeWalls(), 806844323190414);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler215(), 806844323190414);
## --seed-contents--
```js
function euler215() {
function crackFreeWalls() {
return true;
}
euler215();
crackFreeWalls();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-216-investigating-the-primality-of-numbers-of-the-form-2n2-1
# --description--
Consider numbers t(n) of the form t(n) = 2n2-1 with n > 1.
Consider numbers $t(n)$ of the form $t(n) = 2n^2 - 1$ with $n > 1$.
The first such numbers are 7, 17, 31, 49, 71, 97, 127 and 161.
It turns out that only 49 = 7\*7 and 161 = 7\*23 are not prime.
It turns out that only $49 = 7 \times 7$ and $161 = 7 \times 23$ are not prime.
For n ≤ 10000 there are 2202 numbers t(n) that are prime.
For $n ≤ 10000$ there are 2202 numbers $t(n)$ that are prime.
How many numbers t(n) are prime for n ≤ 50,000,000 ?
How many numbers $t(n)$ are prime for $n ≤ 50\\,000\\,000$?
# --hints--
`euler216()` should return 5437849.
`primalityOfNumbers()` should return `5437849`.
```js
assert.strictEqual(euler216(), 5437849);
assert.strictEqual(primalityOfNumbers(), 5437849);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler216(), 5437849);
## --seed-contents--
```js
function euler216() {
function primalityOfNumbers() {
return true;
}
euler216();
primalityOfNumbers();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-217-balanced-numbers
# --description--
A positive integer with k (decimal) digits is called balanced if its first ⌈k/2⌉ digits sum to the same value as its last ⌈k/2⌉ digits, where ⌈x⌉, pronounced ceiling of x, is the smallest integer ≥ x, thus ⌈π⌉ = 4 and ⌈5⌉ = 5.
A positive integer with $k$ (decimal) digits is called balanced if its first $⌈\frac{k}{2}⌉$ digits sum to the same value as its last $⌈\frac{k}{2}⌉$ digits, where $⌈x⌉$, pronounced ceiling of $x$, is the smallest integer $≥ x$, thus $⌈π⌉ = 4$ and $⌈5⌉ = 5$.
So, for example, all palindromes are balanced, as is 13722.
Let T(n) be the sum of all balanced numbers less than 10n.
Let $T(n)$ be the sum of all balanced numbers less than $10^n$.
Thus: T(1) = 45, T(2) = 540 and T(5) = 334795890.
Thus: $T(1) = 45$, $T(2) = 540$ and $T(5) = 334\\,795\\,890$.
Find T(47) mod 315
Find $T(47)\\,mod\\,3^{15}$
# --hints--
`euler217()` should return 6273134.
`balancedNumbers()` should return `6273134`.
```js
assert.strictEqual(euler217(), 6273134);
assert.strictEqual(balancedNumbers(), 6273134);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler217(), 6273134);
## --seed-contents--
```js
function euler217() {
function balancedNumbers() {
return true;
}
euler217();
balancedNumbers();
```
# --solutions--

View File

@ -8,26 +8,32 @@ dashedName: problem-218-perfect-right-angled-triangles
# --description--
Consider the right angled triangle with sides a=7, b=24 and c=25.
Consider the right-angled triangle with sides $a=7$, $b=24$ and $c=25$.
The area of this triangle is 84, which is divisible by the perfect numbers 6 and 28.
Moreover it is a primitive right angled triangle as gcd(a,b)=1 and gcd(b,c)=1.
Moreover it is a primitive right-angled triangle as $gcd(a,b) = 1$ and $gcd(b,c) = 1$.
Also c is a perfect square.
Also $c$ is a perfect square.
We will call a right angled triangle perfect if -it is a primitive right angled triangle -its hypotenuse is a perfect square
We will call a right-angled triangle perfect if:
We will call a right angled triangle super-perfect if -it is a perfect right angled triangle and -its area is a multiple of the perfect numbers 6 and 28.
- it is a primitive right-angled triangle
- its hypotenuse is a perfect square
How many perfect right-angled triangles with c≤1016 exist that are not super-perfect?
We will call a right-angled triangle super-perfect if:
- it is a perfect right-angled triangle
- its area is a multiple of the perfect numbers 6 and 28.
How many perfect right-angled triangles with $c ≤ {10}^{16}$ exist that are not super-perfect?
# --hints--
`euler218()` should return 0.
`perfectRightAngledTriangles()` should return `0`.
```js
assert.strictEqual(euler218(), 0);
assert.strictEqual(perfectRightAngledTriangles(), 0);
```
# --seed--
@ -35,12 +41,12 @@ assert.strictEqual(euler218(), 0);
## --seed-contents--
```js
function euler218() {
function perfectRightAngledTriangles() {
return true;
}
euler218();
perfectRightAngledTriangles();
```
# --solutions--

View File

@ -8,26 +8,26 @@ dashedName: problem-219-skew-cost-coding
# --description--
Let A and B be bit strings (sequences of 0's and 1's).
Let $A$ and $B$ be bit strings (sequences of 0's and 1's).
If A is equal to the leftmost length(A) bits of B, then A is said to be a prefix of B.
If $A$ is equal to the <u>left</u>most length($A$) bits of $B$, then $A$ is said to be a prefix of $B$.
For example, 00110 is a prefix of 001101001, but not of 00111 or 100110.
For example, 00110 is a prefix of <u>00110</u>1001, but not of 00111 or 100110.
A prefix-free code of size n is a collection of n distinct bit strings such that no string is a prefix of any other. For example, this is a prefix-free code of size 6:
A prefix-free code of size $n$ is a collection of $n$ distinct bit strings such that no string is a prefix of any other. For example, this is a prefix-free code of size 6:
0000, 0001, 001, 01, 10, 11
$$0000, 0001, 001, 01, 10, 11$$
Now suppose that it costs one penny to transmit a '0' bit, but four pence to transmit a '1'. Then the total cost of the prefix-free code shown above is 35 pence, which happens to be the cheapest possible for the skewed pricing scheme in question. In short, we write Cost(6) = 35.
Now suppose that it costs one penny to transmit a '0' bit, but four pence to transmit a '1'. Then the total cost of the prefix-free code shown above is 35 pence, which happens to be the cheapest possible for the skewed pricing scheme in question. In short, we write $Cost(6) = 35$.
What is Cost(109) ?
What is $Cost(10^9)$?
# --hints--
`euler219()` should return 64564225042.
`skewCostCoding()` should return `64564225042`.
```js
assert.strictEqual(euler219(), 64564225042);
assert.strictEqual(skewCostCoding(), 64564225042);
```
# --seed--
@ -35,12 +35,12 @@ assert.strictEqual(euler219(), 64564225042);
## --seed-contents--
```js
function euler219() {
function skewCostCoding() {
return true;
}
euler219();
skewCostCoding();
```
# --solutions--

View File

@ -8,24 +8,33 @@ dashedName: problem-220-heighway-dragon
# --description--
Let D0 be the two-letter string "Fa". For n≥1, derive Dn from Dn-1 by the string-rewriting rules:
Let $D_0$ be the two-letter string "Fa". For $n ≥ 1$, derive $D_n$ from $D_{n - 1}$ by the string-rewriting rules:
"a" → "aRbFR" "b" → "LFaLb"
- "a" → "aRbFR"
- "b" → "LFaLb"
Thus, D0 = "Fa", D1 = "FaRbFR", D2 = "FaRbFRRLFaLbFR", and so on.
Thus, $D_0$ = "Fa", $D_1$ = "FaRbFR", $D_2$ = "FaRbFRRLFaLbFR", and so on.
These strings can be interpreted as instructions to a computer graphics program, with "F" meaning "draw forward one unit", "L" meaning "turn left 90 degrees", "R" meaning "turn right 90 degrees", and "a" and "b" being ignored. The initial position of the computer cursor is (0,0), pointing up towards (0,1).
Then Dn is an exotic drawing known as the Heighway Dragon of order n. For example, D10 is shown below; counting each "F" as one step, the highlighted spot at (18,16) is the position reached after 500 steps.
Then $D_n$ is an exotic drawing known as the Heighway Dragon of order $n$. For example, $D_{10}$ is shown below; counting each "F" as one step, the highlighted spot at (18,16) is the position reached after 500 steps.
What is the position of the cursor after 1012 steps in D50 ? Give your answer in the form x,y with no spaces.
<img class="img-responsive center-block" alt="drawing of the Heighway Dragon after 500 steps" src="https://cdn.freecodecamp.org/curriculum/project-euler/heighway-dragon.gif" style="background-color: white; padding: 10px;">
What is the position of the cursor after ${10}^{12}$ steps in $D_{50}$? Give your answer as a string in the form `x,y` with no spaces.
# --hints--
`euler220()` should return 139776, 963904.
`heighwayDragon()` should return a string.
```js
assert.strictEqual(euler220(), 139776, 963904);
assert(typeof heighwayDragon() === 'string');
```
`heighwayDragon()` should return the string `139776,963904`.
```js
assert.strictEqual(heighwayDragon(), '139776,963904');
```
# --seed--
@ -33,12 +42,12 @@ assert.strictEqual(euler220(), 139776, 963904);
## --seed-contents--
```js
function euler220() {
function heighwayDragon() {
return true;
}
euler220();
heighwayDragon();
```
# --solutions--