fix(curriculum): clean-up Project Euler 381-400 (#43024)

* fix: clean-up Project Euler 381-400

* fix: missing image extension

* fix: missing subscripts

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-30 16:59:29 +02:00
committed by GitHub
parent 594adf02c1
commit d269909faa
20 changed files with 279 additions and 180 deletions

View File

@ -8,20 +8,24 @@ dashedName: problem-381-prime-k-factorial
# --description--
For a prime p let S(p) = (∑(p-k)!) mod(p) for 1 ≤ k ≤ 5.
For a prime $p$ let $S(p) = (\sum (p - k)!)\bmod (p)$ for $1 ≤ k ≤ 5$.
For example, if p=7, (7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872. As 872 mod(7) = 4, S(7) = 4.
For example, if $p = 7$,
It can be verified that ∑S(p) = 480 for 5 ≤ p &lt; 100.
$$(7 - 1)! + (7 - 2)! + (7 - 3)! + (7 - 4)! + (7 - 5)! = 6! + 5! + 4! + 3! + 2! = 720 + 120 + 24 + 6 + 2 = 872$$
Find ∑S(p) for 5 ≤ p &lt; 108.
As $872\bmod (7) = 4$, $S(7) = 4$.
It can be verified that $\sum S(p) = 480$ for $5 ≤ p &lt; 100$.
Find $\sum S(p)$ for $5 ≤ p &lt; {10}^8$.
# --hints--
`euler381()` should return 139602943319822.
`primeKFactorial()` should return `139602943319822`.
```js
assert.strictEqual(euler381(), 139602943319822);
assert.strictEqual(primeKFactorial(), 139602943319822);
```
# --seed--
@ -29,12 +33,12 @@ assert.strictEqual(euler381(), 139602943319822);
## --seed-contents--
```js
function euler381() {
function primeKFactorial() {
return true;
}
euler381();
primeKFactorial();
```
# --solutions--

View File

@ -10,22 +10,39 @@ dashedName: problem-382-generating-polygons
A polygon is a flat shape consisting of straight line segments that are joined to form a closed chain or circuit. A polygon consists of at least three sides and does not self-intersect.
A set S of positive numbers is said to generate a polygon P if: no two sides of P are the same length, the length of every side of P is in S, and S contains no other value.
A set $S$ of positive numbers is said to generate a polygon $P$ if:
For example: The set {3, 4, 5} generates a polygon with sides 3, 4, and 5 (a triangle). The set {6, 9, 11, 24} generates a polygon with sides 6, 9, 11, and 24 (a quadrilateral). The sets {1, 2, 3} and {2, 3, 4, 9} do not generate any polygon at all.
- no two sides of $P$ are the same length,
- the length of every side of $P$ is in $S$, and
- $S$ contains no other value.
Consider the sequence s, defined as follows:s1 = 1, s2 = 2, s3 = 3 sn = sn-1 + sn-3 for n > 3.
For example:
Let Un be the set {s1, s2, ..., sn}. For example, U10 = {1, 2, 3, 4, 6, 9, 13, 19, 28, 41}. Let f(n) be the number of subsets of Un which generate at least one polygon. For example, f(5) = 7, f(10) = 501 and f(25) = 18635853.
The set {3, 4, 5} generates a polygon with sides 3, 4, and 5 (a triangle).
Find the last 9 digits of f(1018).
The set {6, 9, 11, 24} generates a polygon with sides 6, 9, 11, and 24 (a quadrilateral).
The sets {1, 2, 3} and {2, 3, 4, 9} do not generate any polygon at all.
Consider the sequence $s$, defined as follows:
- $s_1 = 1$, $s_2 = 2$, $s_3 = 3$
- $s_n = s_{n - 1} + s_{n - 3}$ for $n > 3$.
Let $U_n$ be the set $\\{s_1, s_2, \ldots, s_n\\}$. For example, $U_{10} = \\{1, 2, 3, 4, 6, 9, 13, 19, 28, 41\\}$.
Let $f(n)$ be the number of subsets of $U_n$ which generate at least one polygon.
For example, $f(5) = 7$, $f(10) = 501$ and $f(25) = 18\\,635\\,853$.
Find the last 9 digits of $f({10}^{18})$.
# --hints--
`euler382()` should return 697003956.
`generatingPolygons()` should return `697003956`.
```js
assert.strictEqual(euler382(), 697003956);
assert.strictEqual(generatingPolygons(), 697003956);
```
# --seed--
@ -33,12 +50,12 @@ assert.strictEqual(euler382(), 697003956);
## --seed-contents--
```js
function euler382() {
function generatingPolygons() {
return true;
}
euler382();
generatingPolygons();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-383-divisibility-comparison-between-factorials
# --description--
Let f5(n) be the largest integer x for which 5x divides n.
Let $f_5(n)$ be the largest integer $x$ for which $5^x$ divides $n$.
For example, f5(625000) = 7.
For example, $f_5(625\\,000) = 7$.
Let T5(n) be the number of integers i which satisfy f5((2·i-1)!) &lt; 2·f5(i!) and 1 ≤ i ≤ n. It can be verified that T5(103) = 68 and T5(109) = 2408210.
Let $T_5(n)$ be the number of integers $i$ which satisfy $f_5((2 \times i - 1)!) &lt; 2 \times f_5(i!)$ and $1 ≤ i ≤ n$.
Find T5(1018).
It can be verified that $T_5({10}^3) = 68$ and $T_5({10}^9) = 2\\,408\\,210$.
Find $T_5({10}^{18})$.
# --hints--
`euler383()` should return 22173624649806.
`factorialDivisibilityComparison()` should return `22173624649806`.
```js
assert.strictEqual(euler383(), 22173624649806);
assert.strictEqual(factorialDivisibilityComparison(), 22173624649806);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler383(), 22173624649806);
## --seed-contents--
```js
function euler383() {
function factorialDivisibilityComparison() {
return true;
}
euler383();
factorialDivisibilityComparison();
```
# --solutions--

View File

@ -8,30 +8,46 @@ dashedName: problem-384-rudin-shapiro-sequence
# --description--
Define the sequence a(n) as the number of adjacent pairs of ones in the binary expansion of n (possibly overlapping).
Define the sequence $a(n)$ as the number of adjacent pairs of ones in the binary expansion of $n$ (possibly overlapping).
E.g.: a(5) = a(1012) = 0, a(6) = a(1102) = 1, a(7) = a(1112) = 2
E.g.: $a(5) = a({101}_2) = 0$, $a(6) = a({110}_2) = 1$, $a(7) = a({111}_2) = 2$
Define the sequence b(n) = (-1)a(n). This sequence is called the Rudin-Shapiro sequence. Also consider the summatory sequence of b(n): .
Define the sequence $b(n) = {(-1)}^{a(n)}$. This sequence is called the Rudin-Shapiro sequence.
The first couple of values of these sequences are: n 0 1 2 3 4 5 6 7 a(n) 0 0 0 1 0 0 1 2 b(n) 1 1 1 -1 1 1 -1 1 s(n) 1 2 3 2 3 4 3 4
Also consider the summatory sequence of $b(n)$: $s(n) = \displaystyle\sum_{i = 0}^{n} b(i)$.
The sequence s(n) has the remarkable property that all elements are positive and every positive integer k occurs exactly k times.
The first couple of values of these sequences are:
Define g(t,c), with 1 ≤ c ≤ t, as the index in s(n) for which t occurs for the c'th time in s(n). E.g.: g(3,3) = 6, g(4,2) = 7 and g(54321,12345) = 1220847710.
$$\begin{array}{lr}
n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\\\
a(n) & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 2 \\\\
b(n) & 1 & 1 & 1 & -1 & 1 & 1 & -1 & 1 \\\\
s(n) & 1 & 2 & 3 & 2 & 3 & 4 & 3 & 4
\end{array}$$
Let F(n) be the fibonacci sequence defined by: F(0)=F(1)=1 and F(n)=F(n-1)+F(n-2) for n>1.
The sequence $s(n)$ has the remarkable property that all elements are positive and every positive integer $k$ occurs exactly $k$ times.
Define GF(t)=g(F(t),F(t-1)).
Define $g(t, c)$, with $1 ≤ c ≤ t$, as the index in $s(n)$ for which $t$ occurs for the $c$'th time in $s(n)$.
Find ΣGF(t) for 2≤t≤45.
E.g.: $g(3, 3) = 6$, $g(4, 2) = 7$ and $g(54321, 12345) = 1\\,220\\,847\\,710$.
Let $F(n)$ be the fibonacci sequence defined by:
$$\begin{align}
& F(0) = F(1) = 1 \text{ and} \\\\
& F(n) = F(n - 1) + F(n - 2) \text{ for } n > 1.
\end{align}$$
Define $GF(t) = g(F(t), F(t - 1))$.
Find $\sum GF(t)$ for$ 2 ≤ t ≤ 45$.
# --hints--
`euler384()` should return 3354706415856333000.
`rudinShapiroSequence()` should return `3354706415856333000`.
```js
assert.strictEqual(euler384(), 3354706415856333000);
assert.strictEqual(rudinShapiroSequence(), 3354706415856333000);
```
# --seed--
@ -39,12 +55,12 @@ assert.strictEqual(euler384(), 3354706415856333000);
## --seed-contents--
```js
function euler384() {
function rudinShapiroSequence() {
return true;
}
euler384();
rudinShapiroSequence();
```
# --solutions--

View File

@ -8,29 +8,31 @@ dashedName: problem-385-ellipses-inside-triangles
# --description--
For any triangle T in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside T.
For any triangle $T$ in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside $T$.
For a given n, consider triangles T such that:
<img class="img-responsive center-block" alt="ellipse completely insisde of triangle" src="https://cdn.freecodecamp.org/curriculum/project-euler/ellipses-inside-triangles.png" style="background-color: white; padding: 10px;">
- the vertices of T have integer coordinates with absolute value ≤ n, and
- the foci1 of the largest-area ellipse inside T are (√13,0) and (-√13,0).
For a given $n$, consider triangles $T$ such that:
Let A(n) be the sum of the areas of all such triangles.
- the vertices of $T$ have integer coordinates with absolute value $≤ n$, and
- the foci<sup>1</sup> of the largest-area ellipse inside $T$ are $(\sqrt{13}, 0)$ and $(-\sqrt{13}, 0)$.
For example, if n = 8, there are two such triangles. Their vertices are (-4,-3),(-4,3),(8,0) and (4,3),(4,-3),(-8,0), and the area of each triangle is 36. Thus A(8) = 36 + 36 = 72.
Let $A(n)$ be the sum of the areas of all such triangles.
It can be verified that A(10) = 252, A(100) = 34632 and A(1000) = 3529008.
For example, if $n = 8$, there are two such triangles. Their vertices are (-4,-3), (-4,3), (8,0) and (4,3), (4,-3), (-8,0), and the area of each triangle is 36. Thus $A(8) = 36 + 36 = 72$.
Find A(1 000 000 000).
It can be verified that $A(10) = 252$, $A(100) = 34\\,632$ and $A(1000) = 3\\,529\\,008$.
1The foci (plural of focus) of an ellipse are two points A and B such that for every point P on the boundary of the ellipse, AP + PB is constant.
Find $A(1\\,000\\,000\\,000)$.
<sup>1</sup>The foci (plural of focus) of an ellipse are two points $A$ and $B$ such that for every point $P$ on the boundary of the ellipse, $AP + PB$ is constant.
# --hints--
`euler385()` should return 3776957309612154000.
`ellipsesInsideTriangles()` should return `3776957309612154000`.
```js
assert.strictEqual(euler385(), 3776957309612154000);
assert.strictEqual(ellipsesInsideTriangles(), 3776957309612154000);
```
# --seed--
@ -38,12 +40,12 @@ assert.strictEqual(euler385(), 3776957309612154000);
## --seed-contents--
```js
function euler385() {
function ellipsesInsideTriangles() {
return true;
}
euler385();
ellipsesInsideTriangles();
```
# --solutions--

View File

@ -8,22 +8,26 @@ dashedName: problem-386-maximum-length-of-an-antichain
# --description--
Let n be an integer and S(n) be the set of factors of n.
Let $n$ be an integer and $S(n)$ be the set of factors of $n$.
A subset A of S(n) is called an antichain of S(n) if A contains only one element or if none of the elements of A divides any of the other elements of A.
A subset $A$ of $S(n)$ is called an antichain of $S(n)$ if $A$ contains only one element or if none of the elements of $A$ divides any of the other elements of $A$.
For example: S(30) = {1, 2, 3, 5, 6, 10, 15, 30} {2, 5, 6} is not an antichain of S(30). {2, 3, 5} is an antichain of S(30).
For example: $S(30) = \\{1, 2, 3, 5, 6, 10, 15, 30\\}$
Let N(n) be the maximum length of an antichain of S(n).
$\\{2, 5, 6\\}$ is not an antichain of $S(30)$.
Find ΣN(n) for 1 ≤ n ≤ 108
$\\{2, 3, 5\\}$ is an antichain of $S(30)$.
Let $N(n)$ be the maximum length of an antichain of $S(n)$.
Find $\sum N(n)$ for $1 ≤ n ≤ {10}^8$
# --hints--
`euler386()` should return 528755790.
`maximumLengthOfAntichain()` should return `528755790`.
```js
assert.strictEqual(euler386(), 528755790);
assert.strictEqual(maximumLengthOfAntichain(), 528755790);
```
# --seed--
@ -31,12 +35,12 @@ assert.strictEqual(euler386(), 528755790);
## --seed-contents--
```js
function euler386() {
function maximumLengthOfAntichain() {
return true;
}
euler386();
maximumLengthOfAntichain();
```
# --solutions--

View File

@ -18,20 +18,24 @@ When we truncate the last digit from 20, we get 2, which is also a Harshad numbe
Let's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a right truncatable Harshad number.
Also: 201/3=67 which is prime. Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.
Also:
$\frac{201}{3} = 67$ which is prime.
Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.
Now take the number 2011 which is prime. When we truncate the last digit from it we get 201, a strong Harshad number that is also right truncatable. Let's call such primes strong, right truncatable Harshad primes.
You are given that the sum of the strong, right truncatable Harshad primes less than 10000 is 90619.
Find the sum of the strong, right truncatable Harshad primes less than 1014.
Find the sum of the strong, right truncatable Harshad primes less than ${10}^{14}$.
# --hints--
`euler387()` should return 696067597313468.
`harshadNumbers()` should return `696067597313468`.
```js
assert.strictEqual(euler387(), 696067597313468);
assert.strictEqual(harshadNumbers(), 696067597313468);
```
# --seed--
@ -39,12 +43,12 @@ assert.strictEqual(euler387(), 696067597313468);
## --seed-contents--
```js
function euler387() {
function harshadNumbers() {
return true;
}
euler387();
harshadNumbers();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-388-distinct-lines
# --description--
Consider all lattice points (a,b,c) with 0 ≤ a,b,c ≤ N.
Consider all lattice points ($a$, $b$, $c$) with $0 ≤ a, b, c ≤ N$.
From the origin O(0,0,0) all lines are drawn to the other lattice points. Let D(N) be the number of distinct such lines.
From the origin $O(0, 0, 0)$ all lines are drawn to the other lattice points. Let $D(N)$ be the number of distinct such lines.
You are given that D(1 000 000) = 831909254469114121.
You are given that $D(1\\,000\\,000) = 831\\,909\\,254\\,469\\,114\\,121$.
Find D(1010). Give as your answer the first nine digits followed by the last nine digits.
Find $D({10}^{10})$. Give as your answer the first nine digits followed by the last nine digits.
# --hints--
`euler388()` should return 831907372805130000.
`distinctLines()` should return `831907372805130000`.
```js
assert.strictEqual(euler388(), 831907372805130000);
assert.strictEqual(distinctLines(), 831907372805130000);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler388(), 831907372805130000);
## --seed-contents--
```js
function euler388() {
function distinctLines() {
return true;
}
euler388();
distinctLines();
```
# --solutions--

View File

@ -8,16 +8,24 @@ dashedName: problem-389-platonic-dice
# --description--
An unbiased single 4-sided die is thrown and its value, T, is noted.T unbiased 6-sided dice are thrown and their scores are added together. The sum, C, is noted.C unbiased 8-sided dice are thrown and their scores are added together. The sum, O, is noted.O unbiased 12-sided dice are thrown and their scores are added together. The sum, D, is noted.D unbiased 20-sided dice are thrown and their scores are added together. The sum, I, is noted.
An unbiased single 4-sided die is thrown and its value, $T$, is noted.
Find the variance of I, and give your answer rounded to 4 decimal places.
$T$ unbiased 6-sided dice are thrown and their scores are added together. The sum, $C$, is noted.
$C$ unbiased 8-sided dice are thrown and their scores are added together. The sum, $O$, is noted.
$O$ unbiased 12-sided dice are thrown and their scores are added together. The sum, $D$, is noted.
$D$ unbiased 20-sided dice are thrown and their scores are added together. The sum, $I$, is noted.
Find the variance of $I$, and give your answer rounded to 4 decimal places.
# --hints--
`euler389()` should return 2406376.3623.
`platonicDice()` should return `2406376.3623`.
```js
assert.strictEqual(euler389(), 2406376.3623);
assert.strictEqual(platonicDice(), 2406376.3623);
```
# --seed--
@ -25,12 +33,12 @@ assert.strictEqual(euler389(), 2406376.3623);
## --seed-contents--
```js
function euler389() {
function platonicDice() {
return true;
}
euler389();
platonicDice();
```
# --solutions--

View File

@ -8,24 +8,22 @@ dashedName: problem-390-triangles-with-non-rational-sides-and-integral-area
# --description--
Consider the triangle with sides √5, √65 and √68.
Consider the triangle with sides $\sqrt{5}$, $\sqrt{65}$ and $\sqrt{68}$. It can be shown that this triangle has area 9.
It can be shown that this triangle has area 9.
$S(n)$ is the sum of the areas of all triangles with sides $\sqrt{1 + b^2}$, $\sqrt{1 + c^2}$ and $\sqrt{b^2 + c^2}$ (for positive integers $b$ and $c$) that have an integral area not exceeding $n$.
S(n) is the sum of the areas of all triangles with sides √(1+b2), √(1+c2) and √(b2+c2) (for positive integers b and c ) that have an integral area not exceeding n.
The example triangle has $b = 2$ and $c = 8$.
The example triangle has b=2 and c=8.
$S({10}^6) = 18\\,018\\,206$.
S(106)=18018206.
Find S(1010).
Find $S({10}^{10})$.
# --hints--
`euler390()` should return 2919133642971.
`nonRationalSidesAndIntegralArea()` should return `2919133642971`.
```js
assert.strictEqual(euler390(), 2919133642971);
assert.strictEqual(nonRationalSidesAndIntegralArea(), 2919133642971);
```
# --seed--
@ -33,12 +31,12 @@ assert.strictEqual(euler390(), 2919133642971);
## --seed-contents--
```js
function euler390() {
function nonRationalSidesAndIntegralArea() {
return true;
}
euler390();
nonRationalSidesAndIntegralArea();
```
# --solutions--

View File

@ -8,28 +8,35 @@ dashedName: problem-391-hopping-game
# --description--
Let sk be the number of 1s when writing the numbers from 0 to k in binary.
Let $s_k$ be the number of 1s when writing the numbers from 0 to $k$ in binary.
For example, writing 0 to 5 in binary, we have 0, 1, 10, 11, 100, 101. There are seven 1s, so s5 = 7.
For example, writing 0 to 5 in binary, we have 0, 1, 10, 11, 100, 101. There are seven 1s, so $s_5 = 7$.
The sequence S = {sk : k ≥ 0} starts {0, 1, 2, 4, 5, 7, 9, 12, ...}.
The sequence $S = \\{s_k : k ≥ 0\\}$ starts $\\{0, 1, 2, 4, 5, 7, 9, 12, \ldots\\}$.
A game is played by two players. Before the game starts, a number n is chosen. A counter c starts at 0. At each turn, the player chooses a number from 1 to n (inclusive) and increases c by that number. The resulting value of c must be a member of S. If there are no more valid moves, the player loses.
A game is played by two players. Before the game starts, a number $n$ is chosen. A counter $c$ starts at 0. At each turn, the player chooses a number from 1 to $n$ (inclusive) and increases $c$ by that number. The resulting value of $c$ must be a member of $S$. If there are no more valid moves, the player loses.
For example: Let n = 5. c starts at 0. Player 1 chooses 4, so c becomes 0 + 4 = 4. Player 2 chooses 5, so c becomes 4 + 5 = 9. Player 1 chooses 3, so c becomes 9 + 3 = 12. etc. Note that c must always belong to S, and each player can increase c by at most n.
For example, with $n = 5$ and starting with $c = 0$:
Let M(n) be the highest number the first player can choose at her first turn to force a win, and M(n) = 0 if there is no such move. For example, M(2) = 2, M(7) = 1 and M(20) = 4.
- Player 1 chooses 4, so $c$ becomes $0 + 4 = 4$.
- Player 2 chooses 5, so $c$ becomes $4 + 5 = 9$.
- Player 1 chooses 3, so $c$ becomes $9 + 3 = 12$.
- etc.
Given Σ(M(n))3 = 8150 for 1 ≤ n ≤ 20.
Note that $c$ must always belong to $S$, and each player can increase $c$ by at most $n$.
Find Σ(M(n))3 for 1 ≤ n ≤ 1000.
Let $M(n)$ be the highest number the first player can choose at her first turn to force a win, and $M(n) = 0$ if there is no such move. For example, $M(2) = 2$, $M(7) = 1$ and $M(20) = 4$.
It can be verified $\sum M{(n)}^3 = 8150$ for $1 ≤ n ≤ 20$.
Find $\sum M{(n)}^3$ for $1 ≤ n ≤ 1000$.
# --hints--
`euler391()` should return 61029882288.
`hoppingGame()` should return `61029882288`.
```js
assert.strictEqual(euler391(), 61029882288);
assert.strictEqual(hoppingGame(), 61029882288);
```
# --seed--
@ -37,12 +44,12 @@ assert.strictEqual(euler391(), 61029882288);
## --seed-contents--
```js
function euler391() {
function hoppingGame() {
return true;
}
euler391();
hoppingGame();
```
# --solutions--

View File

@ -12,20 +12,30 @@ A rectilinear grid is an orthogonal grid where the spacing between the gridlines
An example of such grid is logarithmic graph paper.
Consider rectilinear grids in the Cartesian coordinate system with the following properties:The gridlines are parallel to the axes of the Cartesian coordinate system.There are N+2 vertical and N+2 horizontal gridlines. Hence there are (N+1) x (N+1) rectangular cells.The equations of the two outer vertical gridlines are x = -1 and x = 1.The equations of the two outer horizontal gridlines are y = -1 and y = 1.The grid cells are colored red if they overlap with the unit circle, black otherwise.For this problem we would like you to find the positions of the remaining N inner horizontal and N inner vertical gridlines so that the area occupied by the red cells is minimized.
Consider rectilinear grids in the Cartesian coordinate system with the following properties:
E.g. here is a picture of the solution for N = 10:
- The gridlines are parallel to the axes of the Cartesian coordinate system.
- There are $N + 2$ vertical and $N + 2$ horizontal gridlines. Hence there are $(N + 1) \times (N + 1)$ rectangular cells.
- The equations of the two outer vertical gridlines are $x = -1$ and $x = 1$.
- The equations of the two outer horizontal gridlines are $y = -1$ and $y = 1$.
- The grid cells are colored red if they overlap with the unit circle, black otherwise.
The area occupied by the red cells for N = 10 rounded to 10 digits behind the decimal point is 3.3469640797.
For this problem we would like you to find the positions of the remaining $N$ inner horizontal and $N$ inner vertical gridlines so that the area occupied by the red cells is minimized.
Find the positions for N = 400. Give as your answer the area occupied by the red cells rounded to 10 digits behind the decimal point.
E.g. here is a picture of the solution for $N = 10$:
<img class="img-responsive center-block" alt="solution for N = 10" src="https://cdn.freecodecamp.org/curriculum/project-euler/enmeshed-unit-circle.png" style="background-color: white; padding: 10px;">
The area occupied by the red cells for $N = 10$ rounded to 10 digits behind the decimal point is 3.3469640797.
Find the positions for $N = 400$. Give as your answer the area occupied by the red cells rounded to 10 digits behind the decimal point.
# --hints--
`euler392()` should return 3.1486734435.
`enmeshedUnitCircle()` should return `3.1486734435`.
```js
assert.strictEqual(euler392(), 3.1486734435);
assert.strictEqual(enmeshedUnitCircle(), 3.1486734435);
```
# --seed--
@ -33,12 +43,12 @@ assert.strictEqual(euler392(), 3.1486734435);
## --seed-contents--
```js
function euler392() {
function enmeshedUnitCircle() {
return true;
}
euler392();
enmeshedUnitCircle();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-393-migrating-ants
# --description--
An n×n grid of squares contains n2 ants, one ant per square.
An $n × n$ grid of squares contains $n^2$ ants, one ant per square.
All ants decide to move simultaneously to an adjacent square (usually 4 possibilities, except for ants on the edge of the grid or at the corners).
We define f(n) to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.
We define $f(n)$ to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.
You are given that f(4) = 88. Find f(10).
You are given that $f(4) = 88$.
Find $f(10)$.
# --hints--
`euler393()` should return 112398351350823100.
`migratingAnts()` should return `112398351350823100`.
```js
assert.strictEqual(euler393(), 112398351350823100);
assert.strictEqual(migratingAnts(), 112398351350823100);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler393(), 112398351350823100);
## --seed-contents--
```js
function euler393() {
function migratingAnts() {
return true;
}
euler393();
migratingAnts();
```
# --solutions--

View File

@ -12,24 +12,25 @@ Jeff eats a pie in an unusual way.
The pie is circular. He starts with slicing an initial cut in the pie along a radius.
While there is at least a given fraction F of pie left, he performs the following procedure:
While there is at least a given fraction $F$ of pie left, he performs the following procedure:
\- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.
- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.
- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.
\- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.
When less than a fraction $F$ of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.
When less than a fraction F of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.
<img class="img-responsive center-block" alt="animation of pie slicing procedure" src="https://cdn.freecodecamp.org/curriculum/project-euler/eating-pie.gif" style="background-color: white; padding: 10px;">
For x ≥ 1, let E(x) be the expected number of times Jeff repeats the procedure above with F = 1/x. It can be verified that E(1) = 1, E(2) ≈ 1.2676536759, and E(7.5) ≈ 2.1215732071.
For $x ≥ 1$, let $E(x)$ be the expected number of times Jeff repeats the procedure above with $F = \frac{1}{x}$. It can be verified that $E(1) = 1$, $E(2) ≈ 1.2676536759$, and $E(7.5) ≈ 2.1215732071$.
Find E(40) rounded to 10 decimal places behind the decimal point.
Find $E(40)$ rounded to 10 decimal places behind the decimal point.
# --hints--
`euler394()` should return 3.2370342194.
`eatingPie()` should return `3.2370342194`.
```js
assert.strictEqual(euler394(), 3.2370342194);
assert.strictEqual(eatingPie(), 3.2370342194);
```
# --seed--
@ -37,12 +38,12 @@ assert.strictEqual(euler394(), 3.2370342194);
## --seed-contents--
```js
function euler394() {
function eatingPie() {
return true;
}
euler394();
eatingPie();
```
# --solutions--

View File

@ -10,20 +10,26 @@ dashedName: problem-395-pythagorean-tree
The Pythagorean tree is a fractal generated by the following procedure:
Start with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base): Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a 3-4-5 ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation). Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg. Repeat this procedure for both squares, considering as their bases the sides touching the triangle.
Start with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base):
1. Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a 3-4-5 ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation).
2. Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg.
3. Repeat this procedure for both squares, considering as their bases the sides touching the triangle.
The resulting figure, after an infinite number of iterations, is the Pythagorean tree.
<img class="img-responsive center-block" alt="animation showing 8 iterations of the procedure" src="https://cdn.freecodecamp.org/curriculum/project-euler/pythagorean-tree.gif" style="background-color: white; padding: 10px;">
It can be shown that there exists at least one rectangle, whose sides are parallel to the largest square of the Pythagorean tree, which encloses the Pythagorean tree completely.
Find the smallest area possible for such a bounding rectangle, and give your answer rounded to 10 decimal places.
# --hints--
`euler395()` should return 28.2453753155.
`pythagoreanTree()` should return `28.2453753155`.
```js
assert.strictEqual(euler395(), 28.2453753155);
assert.strictEqual(pythagoreanTree(), 28.2453753155);
```
# --seed--
@ -31,12 +37,12 @@ assert.strictEqual(euler395(), 28.2453753155);
## --seed-contents--
```js
function euler395() {
function pythagoreanTree() {
return true;
}
euler395();
pythagoreanTree();
```
# --solutions--

View File

@ -8,30 +8,38 @@ dashedName: problem-396-weak-goodstein-sequence
# --description--
For any positive integer n, the nth weak Goodstein sequence {g1, g2, g3, ...} is defined as:
For any positive integer $n$, the $n$th weak Goodstein sequence $\\{g1, g2, g3, \ldots\\}$ is defined as:
g1 = n
- $g_1 = n$
- for $k > 1$, $g_k$ is obtained by writing $g_{k - 1}$ in base $k$, interpreting it as a base $k + 1$ number, and subtracting 1.
for k > 1, gk is obtained by writing gk-1 in base k, interpreting it as a base k + 1 number, and subtracting 1.
The sequence terminates when $g_k$ becomes 0.
The sequence terminates when gk becomes 0.
For example, the $6$th weak Goodstein sequence is $\\{6, 11, 17, 25, \ldots\\}$:
For example, the 6th weak Goodstein sequence is {6, 11, 17, 25, ...}: g1 = 6. g2 = 11 since 6 = 1102, 1103 = 12, and 12 - 1 = 11. g3 = 17 since 11 = 1023, 1024 = 18, and 18 - 1 = 17. g4 = 25 since 17 = 1014, 1015 = 26, and 26 - 1 = 25.
- $g_1 = 6$.
- $g_2 = 11$ since $6 = 110_2$, $110_3 = 12$, and $12 - 1 = 11$.
- $g_3 = 17$ since $11 = 102_3$, $102_4 = 18$, and $18 - 1 = 17$.
- $g_4 = 25$ since $17 = 101_4$, $101_5 = 26$, and $26 - 1 = 25$.
and so on.
It can be shown that every weak Goodstein sequence terminates.
Let G(n) be the number of nonzero elements in the nth weak Goodstein sequence. It can be verified that G(2) = 3, G(4) = 21 and G(6) = 381. It can also be verified that ΣG(n) = 2517 for 1 ≤ n &lt; 8.
Let $G(n)$ be the number of nonzero elements in the $n$th weak Goodstein sequence.
Find the last 9 digits of ΣG(n) for 1 ≤ n &lt; 16.
It can be verified that $G(2) = 3$, $G(4) = 21$ and $G(6) = 381$.
It can also be verified that $\sum G(n) = 2517$ for $1 ≤ n &lt; 8$.
Find the last 9 digits of $\sum G(n)$ for $1 ≤ n &lt; 16$.
# --hints--
`euler396()` should return 173214653.
`weakGoodsteinSequence()` should return `173214653`.
```js
assert.strictEqual(euler396(), 173214653);
assert.strictEqual(weakGoodsteinSequence(), 173214653);
```
# --seed--
@ -39,12 +47,12 @@ assert.strictEqual(euler396(), 173214653);
## --seed-contents--
```js
function euler396() {
function weakGoodsteinSequence() {
return true;
}
euler396();
weakGoodsteinSequence();
```
# --solutions--

View File

@ -8,18 +8,20 @@ dashedName: problem-397-triangle-on-parabola
# --description--
On the parabola y = x2/k, three points A(a, a2/k), B(b, b2/k) and C(c, c2/k) are chosen.
On the parabola $y = \frac{x^2}{k}$, three points $A(a, \frac{a^2}{k})$, $B(b, \frac{b^2}{k})$ and $C(c, \frac{c^2}{k})$ are chosen.
Let F(K, X) be the number of the integer quadruplets (k, a, b, c) such that at least one angle of the triangle ABC is 45-degree, with 1 ≤ k ≤ K and -X ≤ a &lt; b &lt; c ≤ X.
Let $F(K, X)$ be the number of the integer quadruplets $(k, a, b, c)$ such that at least one angle of the triangle $ABC$ is 45°, with $1 ≤ k ≤ K$ and $-X ≤ a &lt; b &lt; c ≤ X$.
For example, F(1, 10) = 41 and F(10, 100) = 12492. Find F(106, 109).
For example, $F(1, 10) = 41$ and $F(10, 100) = 12\\,492$.
Find $F({10}^6, {10}^9)$.
# --hints--
`euler397()` should return 141630459461893730.
`triangleOnParabola()` should return `141630459461893730`.
```js
assert.strictEqual(euler397(), 141630459461893730);
assert.strictEqual(triangleOnParabola(), 141630459461893730);
```
# --seed--
@ -27,12 +29,12 @@ assert.strictEqual(euler397(), 141630459461893730);
## --seed-contents--
```js
function euler397() {
function triangleOnParabola() {
return true;
}
euler397();
triangleOnParabola();
```
# --solutions--

View File

@ -8,18 +8,18 @@ dashedName: problem-398-cutting-rope
# --description--
Inside a rope of length n, n-1 points are placed with distance 1 from each other and from the endpoints. Among these points, we choose m-1 points at random and cut the rope at these points to create m segments.
Inside a rope of length $n$, $n - 1$ points are placed with distance 1 from each other and from the endpoints. Among these points, we choose $m - 1$ points at random and cut the rope at these points to create $m$ segments.
Let E(n, m) be the expected length of the second-shortest segment. For example, E(3, 2) = 2 and E(8, 3) = 16/7. Note that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.
Let $E(n, m)$ be the expected length of the second-shortest segment. For example, $E(3, 2) = 2$ and $E(8, 3) = \frac{16}{7}$. Note that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.
Find E(107, 100). Give your answer rounded to 5 decimal places behind the decimal point.
Find $E({10}^7, 100)$. Give your answer rounded to 5 decimal places behind the decimal point.
# --hints--
`euler398()` should return 2010.59096.
`cuttingRope()` should return `2010.59096`.
```js
assert.strictEqual(euler398(), 2010.59096);
assert.strictEqual(cuttingRope(), 2010.59096);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler398(), 2010.59096);
## --seed-contents--
```js
function euler398() {
function cuttingRope() {
return true;
}
euler398();
cuttingRope();
```
# --solutions--

View File

@ -10,28 +10,34 @@ dashedName: problem-399-squarefree-fibonacci-numbers
The first 15 fibonacci numbers are:
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610.
$$1,1,2,3,5,8,13,21,34,55,89,144,233,377,610.$$
It can be seen that 8 and 144 are not squarefree: 8 is divisible by 4 and 144 is divisible by 4 and by 9.
So the first 13 squarefree fibonacci numbers are:
1,1,2,3,5,13,21,34,55,89,233,377 and 610.
$$1,1,2,3,5,13,21,34,55,89,233,377 \text{ and } 610.$$
The 200th squarefree fibonacci number is: 971183874599339129547649988289594072811608739584170445. The last sixteen digits of this number are: 1608739584170445 and in scientific notation this number can be written as 9.7e53.
The $200$th squarefree fibonacci number is: 971183874599339129547649988289594072811608739584170445. The last sixteen digits of this number are: 1608739584170445 and in scientific notation this number can be written as `9.7e53`.
Find the 100 000 000th squarefree fibonacci number. Give as your answer its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point). For the 200th squarefree number the answer would have been: 1608739584170445,9.7e53
Find the $100\\,000\\,000$th squarefree fibonacci number. Give as your answer as a string with its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point). For the $200$th squarefree number the answer would have been: `1608739584170445,9.7e53`
Note: For this problem, assume that for every prime p, the first fibonacci number divisible by p is not divisible by p2 (this is part of Wall's conjecture). This has been verified for primes ≤ 3·1015, but has not been proven in general.
**Note:** For this problem, assume that for every prime $p$, the first fibonacci number divisible by $p$ is not divisible by $p^2$ (this is part of Wall's conjecture). This has been verified for primes $≤ 3 \times {10}^{15}$, but has not been proven in general.
If it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the 100 000 000th squarefree fibonacci number, rather it represents only a lower bound for that number.
If it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the $100\\,000\\,000$th squarefree fibonacci number, rather it represents only a lower bound for that number.
# --hints--
`euler399()` should return 1508395636674243, 6.5e27330467.
`squarefreeFibonacciNumbers()` should return a string.
```js
assert.strictEqual(euler399(), 1508395636674243, 6.5e27330467);
assert(typeof squarefreeFibonacciNumbers() === 'string');
```
`squarefreeFibonacciNumbers()` should return the string `1508395636674243,6.5e27330467`.
```js
assert.strictEqual(squarefreeFibonacciNumbers(), '1508395636674243,6.5e27330467');
```
# --seed--
@ -39,12 +45,12 @@ assert.strictEqual(euler399(), 1508395636674243, 6.5e27330467);
## --seed-contents--
```js
function euler399() {
function squarefreeFibonacciNumbers() {
return true;
}
euler399();
squarefreeFibonacciNumbers();
```
# --solutions--

View File

@ -8,28 +8,30 @@ dashedName: problem-400-fibonacci-tree-game
# --description--
A Fibonacci tree is a binary tree recursively defined as:T(0) is the empty tree.
A Fibonacci tree is a binary tree recursively defined as:
T(1) is the binary tree with only one node.
T(k) consists of a root node that has T(k-1) and T(k-2) as children.
- $T(0)$ is the empty tree.
- $T(1)$ is the binary tree with only one node.
- $T(k)$ consists of a root node that has $T(k - 1)$ and $T(k - 2)$ as children.
On such a tree two players play a take-away game. On each turn a player selects a node and removes that node along with the subtree rooted at that node. The player who is forced to take the root node of the entire tree loses.
Here are the winning moves of the first player on the first turn for T(k) from k=1 to k=6.
Here are the winning moves of the first player on the first turn for $T(k)$ from $k = 1$ to $k = 6$.
Let f(k) be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on T(k).
<img class="img-responsive center-block" alt="winning moves of first player, on the first turn for k = 1 to k = 6" src="https://cdn.freecodecamp.org/curriculum/project-euler/fibonacci-tree-game.png" style="background-color: white; padding: 10px;">
For example, f(5) = 1 and f(10) = 17.
Let $f(k)$ be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on $T(k)$.
Find f(10000). Give the last 18 digits of your answer.
For example, $f(5) = 1$ and $f(10) = 17$.
Find $f(10000)$. Give the last 18 digits of your answer.
# --hints--
`euler400()` should return 438505383468410600.
`fibonacciTreeGame()` should return `438505383468410600`.
```js
assert.strictEqual(euler400(), 438505383468410600);
assert.strictEqual(fibonacciTreeGame(), 438505383468410600);
```
# --seed--
@ -37,12 +39,12 @@ assert.strictEqual(euler400(), 438505383468410600);
## --seed-contents--
```js
function euler400() {
function fibonacciTreeGame() {
return true;
}
euler400();
fibonacciTreeGame();
```
# --solutions--