fix(curriculum): clean-up Project Euler 241-260 (#42879)

* fix: clean-up Project Euler 241-260

* fix: typo

* Update curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-255-rounded-square-roots.md

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
gikf
2021-07-16 12:21:45 +02:00
committed by GitHub
parent b2059684ef
commit 67de105117
20 changed files with 272 additions and 154 deletions

View File

@ -8,18 +8,20 @@ dashedName: problem-241-perfection-quotients
# --description--
For a positive integer n, let σ(n) be the sum of all divisors of n, so e.g. σ(6) = 1 + 2 + 3 + 6 = 12.
For a positive integer $n$, let $σ(n)$ be the sum of all divisors of $n$, so e.g. $σ(6) = 1 + 2 + 3 + 6 = 12$.
A perfect number, as you probably know, is a number with σ(n) = 2n.
A perfect number, as you probably know, is a number with $σ(n) = 2n$.
Let us define the perfection quotient of a positive integer asp(n)= σ(n)n . Find the sum of all positive integers n ≤ 1018 for which p(n) has the form k + 12, where k is an integer.
Let us define the perfection quotient of a positive integer as $p(n) = \frac{σ(n)}{n}$.
Find the sum of all positive integers $n ≤ {10}^{18}$ for which $p(n)$ has the form $k + \frac{1}{2}$, where $k$ is an integer.
# --hints--
`euler241()` should return 482316491800641150.
`perfectionQuotients()` should return `482316491800641150`.
```js
assert.strictEqual(euler241(), 482316491800641150);
assert.strictEqual(perfectionQuotients(), 482316491800641150);
```
# --seed--
@ -27,12 +29,12 @@ assert.strictEqual(euler241(), 482316491800641150);
## --seed-contents--
```js
function euler241() {
function perfectionQuotients() {
return true;
}
euler241();
perfectionQuotients();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-242-odd-triplets
# --description--
Given the set {1,2,...,n}, we define f(n,k) as the number of its k-element subsets with an odd sum of elements. For example, f(5,3) = 4, since the set {1,2,3,4,5} has four 3-element subsets having an odd sum of elements, i.e.: {1,2,4}, {1,3,5}, {2,3,4} and {2,4,5}.
Given the set {1,2,..., $n$}, we define $f(n, k)$ as the number of its $k$-element subsets with an odd sum of elements. For example, $f(5,3) = 4$, since the set {1,2,3,4,5} has four 3-element subsets having an odd sum of elements, i.e.: {1,2,4}, {1,3,5}, {2,3,4} and {2,4,5}.
When all three values n, k and f(n,k) are odd, we say that they make an odd-triplet \[n,k,f(n,k)].
When all three values $n$, $k$ and $f(n, k)$ are odd, we say that they make an odd-triplet $[n, k, f(n, k)]$.
There are exactly five odd-triplets with n ≤ 10, namely: \[1,1,f(1,1) = 1], \[5,1,f(5,1) = 3], \[5,5,f(5,5) = 1], \[9,1,f(9,1) = 5] and \[9,9,f(9,9) = 1].
There are exactly five odd-triplets with $n ≤ 10$, namely: $[1, 1, f(1, 1) = 1]$, $[5, 1, f(5, 1) = 3]$, $[5, 5, f(5, 5) = 1]$, $[9, 1, f(9, 1) = 5]$ and $[9, 9, f(9, 9) = 1]$.
How many odd-triplets are there with n ≤ 1012 ?
How many odd-triplets are there with $n ≤ {10}^{12}$?
# --hints--
`euler242()` should return 997104142249036700.
`oddTriplets()` should return `997104142249036700`.
```js
assert.strictEqual(euler242(), 997104142249036700);
assert.strictEqual(oddTriplets(), 997104142249036700);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler242(), 997104142249036700);
## --seed-contents--
```js
function euler242() {
function oddTriplets() {
return true;
}
euler242();
oddTriplets();
```
# --solutions--

View File

@ -10,18 +10,24 @@ dashedName: problem-243-resilience
A positive fraction whose numerator is less than its denominator is called a proper fraction.
For any denominator, d, there will be d1 proper fractions; for example, with d = 12:1/12 , 2/12 , 3/12 , 4/12 , 5/12 , 6/12 , 7/12 , 8/12 , 9/12 , 10/12 , 11/12 .
For any denominator, $d$, there will be $d1$ proper fractions; for example, with $d = 12$:
We shall call a fraction that cannot be cancelled down a resilient fraction. Furthermore we shall define the resilience of a denominator, R(d), to be the ratio of its proper fractions that are resilient; for example, R(12) = 4/11 . In fact, d = 12 is the smallest denominator having a resilience R(d) &lt; 4/10 .
$$\frac{1}{12}, \frac{2}{12}, \frac{3}{12}, \frac{4}{12}, \frac{5}{12}, \frac{6}{12}, \frac{7}{12}, \frac{8}{12}, \frac{9}{12}, \frac{10}{12}, \frac{11}{12}$$
Find the smallest denominator d, having a resilience R(d) &lt; 15499/94744 .
We shall call a fraction that cannot be cancelled down a resilient fraction.
Furthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = \frac{4}{11}$.
In fact, $d = 12$ is the smallest denominator having a resilience $R(d) &lt; \frac{4}{10}$.
Find the smallest denominator $d$, having a resilience $R(d) &lt; \frac{15\\,499}{94\\,744}$.
# --hints--
`euler243()` should return 892371480.
`resilience()` should return `892371480`.
```js
assert.strictEqual(euler243(), 892371480);
assert.strictEqual(resilience(), 892371480);
```
# --seed--
@ -29,12 +35,12 @@ assert.strictEqual(euler243(), 892371480);
## --seed-contents--
```js
function euler243() {
function resilience() {
return true;
}
euler243();
resilience();
```
# --solutions--

View File

@ -10,28 +10,42 @@ dashedName: problem-244-sliders
You probably know the game Fifteen Puzzle. Here, instead of numbered tiles, we have seven red tiles and eight blue tiles.
A move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration (S), by the sequence LULUR we reach the configuration (E):
A move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration ($S$), by the sequence $LULUR$ we reach the configuration ($E$):
(S), (E)
($S$) <img class="img-responsive" alt="configuration S" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-1.gif" style="display: inline-block; background-color: white; padding: 10px;">, ($E$) <img class="img-responsive" alt="configuration E" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-2.gif" style="display: inline-block; background-color: white; padding: 10px;">
For each path, its checksum is calculated by (pseudocode):
checksum = 0 checksum = (checksum × 243 + m1) mod 100 000 007 checksum = (checksum × 243 + m2) mod 100 000 007 … checksum = (checksum × 243 + mn) mod 100 000 007 where mk is the ASCII value of the kth letter in the move sequence and the ASCII values for the moves are:
$$\begin{align}
& \text{checksum} = 0 \\\\
& \text{checksum} = (\text{checksum} × 243 + m_1) \\; \text{mod} \\; 100\\,000\\,007 \\\\
& \text{checksum} = (\text{checksum} × 243 + m_2) \\; \text{mod} \\; 100\\,000\\,007 \\\\
& \ldots \\\\
& \text{checksum} = (\text{checksum} × 243 + m_n) \\; \text{mod} \\; 100\\,000\\,007
\end{align}$$
L76R82U85D68
where $m_k$ is the ASCII value of the $k^{\text{th}}$ letter in the move sequence and the ASCII values for the moves are:
For the sequence LULUR given above, the checksum would be 19761398. Now, starting from configuration (S), find all shortest ways to reach configuration (T).
$$\begin{array}{|c|c|}
\hline
L & 76 \\\\ \hline
R & 82 \\\\ \hline
U & 85 \\\\ \hline
D & 68 \\\\ \hline
\end{array}$$
(S), (T)
For the sequence $LULUR$ given above, the checksum would be 19761398. Now, starting from configuration ($S$), find all shortest ways to reach configuration ($T$).
($S$) <img class="img-responsive center-block" alt="configuration S" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-3.gif" style="display: inline-block; background-color: white; padding: 10px;">, ($T$) <img class="img-responsive center-block" alt="configuration T" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-4.gif" style="display: inline-block; background-color: white; padding: 10px;">
What is the sum of all checksums for the paths having the minimal length?
# --hints--
`euler244()` should return 96356848.
`sliders()` should return `96356848`.
```js
assert.strictEqual(euler244(), 96356848);
assert.strictEqual(sliders(), 96356848);
```
# --seed--
@ -39,12 +53,12 @@ assert.strictEqual(euler244(), 96356848);
## --seed-contents--
```js
function euler244() {
function sliders() {
return true;
}
euler244();
sliders();
```
# --solutions--

View File

@ -8,16 +8,24 @@ dashedName: problem-245-coresilience
# --description--
We shall call a fraction that cannot be cancelled down a resilient fraction. Furthermore we shall define the resilience of a denominator, R(d), to be the ratio of its proper fractions that are resilient; for example, R(12) = 411.
We shall call a fraction that cannot be cancelled down a resilient fraction.
The resilience of a number d > 1 is then φ(d)d 1 , where φ is Euler's totient function. We further define the coresilience of a number n > 1 as C(n)= n φ(n)n 1. The coresilience of a prime p is C(p) = 1p 1. Find the sum of all composite integers 1 &lt; n ≤ 2×1011, for which C(n) is a unit fraction.
Furthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = \frac{4}{11}$.
The resilience of a number $d > 1$ is then $\frac{φ(d)}{d 1}$ , where $φ$ is Euler's totient function.
We further define the coresilience of a number $n > 1$ as $C(n) = \frac{n φ(n)}{n 1}$.
The coresilience of a prime $p$ is $C(p) = \frac{1}{p 1}$.
Find the sum of all composite integers $1 &lt; n ≤ 2 × {10}^{11}$, for which $C(n)$ is a unit fraction.
# --hints--
`euler245()` should return 288084712410001.
`coresilience()` should return `288084712410001`.
```js
assert.strictEqual(euler245(), 288084712410001);
assert.strictEqual(coresilience(), 288084712410001);
```
# --seed--
@ -25,12 +33,12 @@ assert.strictEqual(euler245(), 288084712410001);
## --seed-contents--
```js
function euler245() {
function coresilience() {
return true;
}
euler245();
coresilience();
```
# --solutions--

View File

@ -10,20 +10,32 @@ dashedName: problem-246-tangents-to-an-ellipse
A definition for an ellipse is:
Given a circle c with centre M and radius r and a point G such that d(G,M)
Given a circle $c$ with centre $M$ and radius $r$ and a point $G$ such that $d(G, M) < r$, the locus of the points that are equidistant from $c$ and $G$ form an ellipse.
The construction of the points of the ellipse is shown below.
Given are the points M(-2000,1500) and G(8000,1500). Given is also the circle c with centre M and radius 15000. The locus of the points that are equidistant from G and c form an ellipse e. From a point P outside e the two tangents t1 and t2 to the ellipse are drawn. Let the points where t1 and t2 touch the ellipse be R and S.
<img class="img-responsive center-block" alt="animation of ellipse construction" src="https://cdn.freecodecamp.org/curriculum/project-euler/tangents-to-an-ellipse-1.gif" style="background-color: white; padding: 10px;">
For how many lattice points P is angle RPS greater than 45 degrees?
Given are the points $M(-2000, 1500)$ and $G(8000, 1500)$.
Given is also the circle $c$ with centre $M$ and radius $15\\,000$.
The locus of the points that are equidistant from $G$ and $c$ form an ellipse $e$.
From a point $P$ outside $e$ the two tangents $t_1$ and $t_2$ to the ellipse are drawn.
Let the points where $t_1$ and $t_2$ touch the ellipse be $R$ and $S$.
<img class="img-responsive center-block" alt="circle c with the centre M, radius 15000, and point P outsie of ellipse e; from point P two tangents t_1 and t_2 are drawn to the ellipse, with points touching ellipse are R and S" src="https://cdn.freecodecamp.org/curriculum/project-euler/tangents-to-an-ellipse-2.gif" style="background-color: white; padding: 10px;">
For how many lattice points $P$ is angle $RPS$ greater than 45°?
# --hints--
`euler246()` should return 810834388.
`tangentsToAnEllipse()` should return `810834388`.
```js
assert.strictEqual(euler246(), 810834388);
assert.strictEqual(tangentsToAnEllipse(), 810834388);
```
# --seed--
@ -31,12 +43,12 @@ assert.strictEqual(euler246(), 810834388);
## --seed-contents--
```js
function euler246() {
function tangentsToAnEllipse() {
return true;
}
euler246();
tangentsToAnEllipse();
```
# --solutions--

View File

@ -8,20 +8,32 @@ dashedName: problem-247-squares-under-a-hyperbola
# --description--
Consider the region constrained by 1 ≤ x and 0 ≤ y ≤ 1/x.
Consider the region constrained by $1 ≤ x$ and $0 ≤ y ≤ \frac{1}{x}$.
Let S1 be the largest square that can fit under the curve. Let S2 be the largest square that fits in the remaining area, and so on. Let the index of Sn be the pair (left, below) indicating the number of squares to the left of Sn and the number of squares below Sn.
Let $S_1$ be the largest square that can fit under the curve.
The diagram shows some such squares labelled by number. S2 has one square to its left and none below, so the index of S2 is (1,0). It can be seen that the index of S32 is (1,1) as is the index of S50. 50 is the largest n for which the index of Sn is (1,1).
Let $S_2$ be the largest square that fits in the remaining area, and so on.
What is the largest n for which the index of Sn is (3,3)?
Let the index of $S_n$ be the pair (left, below) indicating the number of squares to the left of $S_n$ and the number of squares below $S_n$.
<img class="img-responsive center-block" alt="diagram with squares under the hyperbola" src="https://cdn.freecodecamp.org/curriculum/project-euler/squares-under-a-hyperbola.gif" style="background-color: white; padding: 10px;">
The diagram shows some such squares labelled by number.
$S_2$ has one square to its left and none below, so the index of $S_2$ is (1, 0).
It can be seen that the index of $S_{32}$ is (1,1) as is the index of $S_{50}$.
50 is the largest $n$ for which the index of $S_n$ is (1, 1).
What is the largest $n$ for which the index of $S_n$ is (3, 3)?
# --hints--
`euler247()` should return 782252.
`squaresUnderAHyperbola()` should return `782252`.
```js
assert.strictEqual(euler247(), 782252);
assert.strictEqual(squaresUnderAHyperbola(), 782252);
```
# --seed--
@ -29,12 +41,12 @@ assert.strictEqual(euler247(), 782252);
## --seed-contents--
```js
function euler247() {
function squaresUnderAHyperbola() {
return true;
}
euler247();
squaresUnderAHyperbola();
```
# --solutions--

View File

@ -8,16 +8,16 @@ dashedName: problem-248-numbers-for-which-eulers-totient-function-equals-13
# --description--
The first number n for which φ(n)=13! is 6227180929.
The first number $n$ for which $φ(n) = 13!$ is $6\\,227\\,180\\,929$.
Find the 150,000th such number.
Find the ${150\\,000}^{\text{th}}$ such number.
# --hints--
`euler248()` should return 23507044290.
`eulersTotientFunctionEquals()` should return `23507044290`.
```js
assert.strictEqual(euler248(), 23507044290);
assert.strictEqual(eulersTotientFunctionEquals(), 23507044290);
```
# --seed--
@ -25,12 +25,12 @@ assert.strictEqual(euler248(), 23507044290);
## --seed-contents--
```js
function euler248() {
function eulersTotientFunctionEquals() {
return true;
}
euler248();
eulersTotientFunctionEquals();
```
# --solutions--

View File

@ -8,18 +8,18 @@ dashedName: problem-249-prime-subset-sums
# --description--
Let S = {2, 3, 5, ..., 4999} be the set of prime numbers less than 5000.
Let $S = \\{2, 3, 5, \ldots, 4999\\}$ be the set of prime numbers less than 5000.
Find the number of subsets of S, the sum of whose elements is a prime number.
Find the number of subsets of $S$, the sum of whose elements is a prime number.
Enter the rightmost 16 digits as your answer.
# --hints--
`euler249()` should return 9275262564250418.
`primeSubsetSums()` should return `9275262564250418`.
```js
assert.strictEqual(euler249(), 9275262564250418);
assert.strictEqual(primeSubsetSums(), 9275262564250418);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler249(), 9275262564250418);
## --seed-contents--
```js
function euler249() {
function primeSubsetSums() {
return true;
}
euler249();
primeSubsetSums();
```
# --solutions--

View File

@ -8,14 +8,14 @@ dashedName: problem-250-250250
# --description--
Find the number of non-empty subsets of {11, 22, 33,..., 250250250250}, the sum of whose elements is divisible by 250. Enter the rightmost 16 digits as your answer.
Find the number of non-empty subsets of $\\{11, 22, 33, \ldots, {250250}^{250250}\\}$, the sum of whose elements is divisible by 250. Enter the rightmost 16 digits as your answer.
# --hints--
`euler250()` should return 1425480602091519.
`twoHundredFifty()` should return `1425480602091519`.
```js
assert.strictEqual(euler250(), 1425480602091519);
assert.strictEqual(twoHundredFifty(), 1425480602091519);
```
# --seed--
@ -23,12 +23,12 @@ assert.strictEqual(euler250(), 1425480602091519);
## --seed-contents--
```js
function euler250() {
function twoHundredFifty() {
return true;
}
euler250();
twoHundredFifty();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-251-cardano-triplets
# --description--
A triplet of positive integers (a,b,c) is called a Cardano Triplet if it satisfies the condition:
A triplet of positive integers ($a$,$b$,$c$) is called a Cardano Triplet if it satisfies the condition:
$$\sqrt[3]{a + b \sqrt{c}} + \sqrt[3]{a - b \sqrt{c}} = 1$$
For example, (2,1,5) is a Cardano Triplet.
There exist 149 Cardano Triplets for which a+b+c ≤ 1000.
There exist 149 Cardano Triplets for which $a + b + c ≤ 1000$.
Find how many Cardano Triplets exist such that a+b+c ≤ 110,000,000.
Find how many Cardano Triplets exist such that $a + b + c ≤ 110\\,000\\,000$.
# --hints--
`euler251()` should return 18946051.
`cardanoTriplets()` should return `18946051`.
```js
assert.strictEqual(euler251(), 18946051);
assert.strictEqual(cardanoTriplets(), 18946051);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler251(), 18946051);
## --seed-contents--
```js
function euler251() {
function cardanoTriplets() {
return true;
}
euler251();
cardanoTriplets();
```
# --solutions--

View File

@ -12,9 +12,15 @@ Given a set of points on a plane, we define a convex hole to be a convex polygon
As an example, the image below shows a set of twenty points and a few such convex holes. The convex hole shown as a red heptagon has an area equal to 1049694.5 square units, which is the highest possible area for a convex hole on the given set of points.
For our example, we used the first 20 points (T2k1, T2k), for k = 1,2,…,20, produced with the pseudo-random number generator:
<img class="img-responsive center-block" alt="set of twenty points and convex holes on plane" src="https://cdn.freecodecamp.org/curriculum/project-euler/convex-holes.gif" style="background-color: white; padding: 10px;">
S0 = 290797 Sn+1 = Sn2 mod 50515093 Tn = ( Sn mod 2000 ) 1000
For our example, we used the first 20 points ($T_{2k 1}$, $T_{2k}$), for $k = 1, 2, \ldots, 20$, produced with the pseudo-random number generator:
$$\begin{align}
S_0 & = 290\\,797 \\\\
S_{n+1} & = {S_n}^2 \\; \text{mod} \\; 50\\,515\\,093 \\\\
T_n & = (S_n \\; \text{mod} \\; 2000) 1000
\end{align}$$
i.e. (527, 144), (488, 732), (454, 947), …
@ -22,10 +28,10 @@ What is the maximum area for a convex hole on the set containing the first 500 p
# --hints--
`euler252()` should return 104924.
`convexHoles()` should return `104924`.
```js
assert.strictEqual(euler252(), 104924);
assert.strictEqual(convexHoles(), 104924);
```
# --seed--
@ -33,12 +39,12 @@ assert.strictEqual(euler252(), 104924);
## --seed-contents--
```js
function euler252() {
function convexHoles() {
return true;
}
euler252();
convexHoles();
```
# --solutions--

View File

@ -8,28 +8,45 @@ dashedName: problem-253-tidying-up
# --description--
A small child has a number caterpillar consisting of forty jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers 1 to 40 in order.
A small child has a "number caterpillar" consisting of forty jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers 1 to 40 in order.
Every night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order. As the caterpillar is built up in this way, it forms distinct segments that gradually merge together. The number of segments starts at zero (no pieces placed), generally increases up to about eleven or twelve, then tends to drop again before finishing at a single segment (all pieces placed).
Every night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.
As the caterpillar is built up in this way, it forms distinct segments that gradually merge together. The number of segments starts at zero (no pieces placed), generally increases up to about eleven or twelve, then tends to drop again before finishing at a single segment (all pieces placed).
For example:
Piece Placed Segments So Far121422936434554354……
| Piece Placed | Segments So Far |
| -------------|-----------------|
| 12 | 1 |
| 4 | 2 |
| 29 | 3 |
| 6 | 4 |
| 34 | 5 |
| 5 | 4 |
| 35 | 4 |
| … | … |
Let M be the maximum number of segments encountered during a random tidy-up of the caterpillar. For a caterpillar of ten pieces, the number of possibilities for each M is
Let $M$ be the maximum number of segments encountered during a random tidy-up of the caterpillar. For a caterpillar of ten pieces, the number of possibilities for each $M$ is
M Possibilities1512 2250912 31815264 41418112 5144000
| M | Possibilities |
|---|---------------|
| 1 | 512 |
| 2 | 250912 |
| 3 | 1815264 |
| 4 | 1418112 |
| 5 | 144000 |
so the most likely value of M is 3 and the average value is 385643113400 = 3.400732, rounded to six decimal places.
so the most likely value of $M$ is 3 and the average value is $\frac{385\\,643}{113\\,400} = 3.400732$, rounded to six decimal places.
The most likely value of M for a forty-piece caterpillar is 11; but what is the average value of M? Give your answer rounded to six decimal places.
The most likely value of $M$ for a forty-piece caterpillar is 11; but what is the average value of $M$? Give your answer rounded to six decimal places.
# --hints--
`euler253()` should return 11.492847.
`tidyingUp()` should return `11.492847`.
```js
assert.strictEqual(euler253(), 11.492847);
assert.strictEqual(tidyingUp(), 11.492847);
```
# --seed--
@ -37,12 +54,12 @@ assert.strictEqual(euler253(), 11.492847);
## --seed-contents--
```js
function euler253() {
function tidyingUp() {
return true;
}
euler253();
tidyingUp();
```
# --solutions--

View File

@ -8,24 +8,24 @@ dashedName: problem-254-sums-of-digit-factorials
# --description--
Define f(n) as the sum of the factorials of the digits of n. For example, f(342) = 3! + 4! + 2! = 32.
Define $f(n)$ as the sum of the factorials of the digits of $n$. For example, $f(342) = 3! + 4! + 2! = 32$.
Define sf(n) as the sum of the digits of f(n). So sf(342) = 3 + 2 = 5.
Define $sf(n)$ as the sum of the digits of $f(n)$. So $sf(342) = 3 + 2 = 5$.
Define g(i) to be the smallest positive integer n such that sf(n) = i. Though sf(342) is 5, sf(25) is also 5, and it can be verified that g(5) is 25.
Define $g(i)$ to be the smallest positive integer $n$ such that $sf(n) = i$. Though $sf(342)$ is 5, $sf(25)$ is also 5, and it can be verified that $g(5)$ is 25.
Define sg(i) as the sum of the digits of g(i). So sg(5) = 2 + 5 = 7.
Define $sg(i)$ as the sum of the digits of $g(i)$. So $sg(5) = 2 + 5 = 7$.
Further, it can be verified that g(20) is 267 and sg(i) for 1 ≤ i ≤ 20 is 156.
Further, it can be verified that $g(20)$ is 267 and $\sum sg(i)$ for $1 ≤ i ≤ 20$ is 156.
What is sg(i) for 1 ≤ i ≤ 150?
What is $\sum sg(i)$ for $1 ≤ i ≤ 150$?
# --hints--
`euler254()` should return 8184523820510.
`sumsOfDigitFactorials()` should return `8184523820510`.
```js
assert.strictEqual(euler254(), 8184523820510);
assert.strictEqual(sumsOfDigitFactorials(), 8184523820510);
```
# --seed--
@ -33,12 +33,12 @@ assert.strictEqual(euler254(), 8184523820510);
## --seed-contents--
```js
function euler254() {
function sumsOfDigitFactorials() {
return true;
}
euler254();
sumsOfDigitFactorials();
```
# --solutions--

View File

@ -8,26 +8,43 @@ dashedName: problem-255-rounded-square-roots
# --description--
We define the rounded-square-root of a positive integer n as the square root of n rounded to the nearest integer.
We define the rounded-square-root of a positive integer $n$ as the square root of $n$ rounded to the nearest integer.
The following procedure (essentially Heron's method adapted to integer arithmetic) finds the rounded-square-root of n: Let d be the number of digits of the number n. If d is odd, set x0 = 2×10(d-1)2. If d is even, set x0 = 7×10(d-2)2. Repeat:
The following procedure (essentially Heron's method adapted to integer arithmetic) finds the rounded-square-root of $n$:
until xk+1 = xk.
Let $d$ be the number of digits of the number $n$.
As an example, let us find the rounded-square-root of n = 4321.n has 4 digits, so x0 = 7×10(4-2)2 = 70. Since x2 = x1, we stop here. So, after just two iterations, we have found that the rounded-square-root of 4321 is 66 (the actual square root is 65.7343137…).
If $d$ is odd, set $x_0 = 2 × {10}^{\frac{d - 1}{2}}$.
The number of iterations required when using this method is surprisingly low. For example, we can find the rounded-square-root of a 5-digit integer (10,000 ≤ n ≤ 99,999) with an average of 3.2102888889 iterations (the average value was rounded to 10 decimal places).
If $d$ is even, set $x_0 = 7 × {10}^{\frac{d - 2}{2}}$.
Using the procedure described above, what is the average number of iterations required to find the rounded-square-root of a 14-digit number (1013 ≤ n &lt; 1014)? Give your answer rounded to 10 decimal places.
Repeat:
Note: The symbols ⌊x⌋ and ⌈x⌉ represent the floor function and ceiling function respectively.
$$x_{k + 1} = \left\lfloor\frac{x_k + \left\lceil\frac{n}{x_k}\right\rceil}{2}\right\rfloor$$
until $x_{k + 1} = x_k$.
As an example, let us find the rounded-square-root of $n = 4321$.
$n$ has 4 digits, so $x_0 = 7 × {10}^{\frac{4-2}{2}} = 70$.
$$x_1 = \left\lfloor\frac{70 + \left\lceil\frac{4321}{70}\right\rceil}{2}\right\rfloor = 66 \\\\
x_2 = \left\lfloor\frac{66 + \left\lceil\frac{4321}{66}\right\rceil}{2}\right\rfloor = 66$$
Since $x_2 = x_1$, we stop here. So, after just two iterations, we have found that the rounded-square-root of 4321 is 66 (the actual square root is 65.7343137…).
The number of iterations required when using this method is surprisingly low. For example, we can find the rounded-square-root of a 5-digit integer ($10\\,000 ≤ n ≤ 99\\,999$) with an average of 3.2102888889 iterations (the average value was rounded to 10 decimal places).
Using the procedure described above, what is the average number of iterations required to find the rounded-square-root of a 14-digit number (${10}^{13} ≤ n &lt; {10}^{14}$)? Give your answer rounded to 10 decimal places.
**Note:** The symbols $⌊x⌋$ and $⌈x⌉$ represent the floor function and ceiling function respectively.
# --hints--
`euler255()` should return 4.447401118.
`roundedSquareRoots()` should return `4.447401118`.
```js
assert.strictEqual(euler255(), 4.447401118);
assert.strictEqual(roundedSquareRoots(), 4.447401118);
```
# --seed--
@ -35,12 +52,12 @@ assert.strictEqual(euler255(), 4.447401118);
## --seed-contents--
```js
function euler255() {
function roundedSquareRoots() {
return true;
}
euler255();
roundedSquareRoots();
```
# --solutions--

View File

@ -12,26 +12,28 @@ Tatami are rectangular mats, used to completely cover the floor of a room, witho
Assuming that the only type of available tatami has dimensions 1×2, there are obviously some limitations for the shape and size of the rooms that can be covered.
For this problem, we consider only rectangular rooms with integer dimensions a, b and even size s = a·b. We use the term 'size' to denote the floor surface area of the room, and — without loss of generality — we add the condition a ≤ b.
For this problem, we consider only rectangular rooms with integer dimensions $a$, $b$ and even size $s = a \times b$. We use the term 'size' to denote the floor surface area of the room, and — without loss of generality — we add the condition $a ≤ b$.
There is one rule to follow when laying out tatami: there must be no points where corners of four different mats meet. For example, consider the two arrangements below for a 4×4 room:
The arrangement on the left is acceptable, whereas the one on the right is not: a red "X" in the middle, marks the point where four tatami meet.
<img class="img-responsive center-block" alt="two arragements of mats in 4x4 room" src="https://cdn.freecodecamp.org/curriculum/project-euler/tatami-free-rooms.gif" style="background-color: white; padding: 10px;">
Because of this rule, certain even-sized rooms cannot be covered with tatami: we call them tatami-free rooms. Further, we define T(s) as the number of tatami-free rooms of size s.
The arrangement on the left is acceptable, whereas the one on the right is not: a red "<strong><span style="color: red;">X</span></strong>" in the middle, marks the point where four tatami meet.
The smallest tatami-free room has size s = 70 and dimensions 7×10. All the other rooms of size s = 70 can be covered with tatami; they are: 1×70, 2×35 and 5×14. Hence, T(70) = 1.
Because of this rule, certain even-sized rooms cannot be covered with tatami: we call them tatami-free rooms. Further, we define $T(s)$ as the number of tatami-free rooms of size $s$.
Similarly, we can verify that T(1320) = 5 because there are exactly 5 tatami-free rooms of size s = 1320: 20×66, 22×60, 24×55, 30×44 and 33×40. In fact, s = 1320 is the smallest room-size s for which T(s) = 5.
The smallest tatami-free room has size $s = 70$ and dimensions 7×10. All the other rooms of size $s = 70$ can be covered with tatami; they are: 1×70, 2×35 and 5×14. Hence, $T(70) = 1$.
Find the smallest room-size s for which T(s) = 200.
Similarly, we can verify that $T(1320) = 5$ because there are exactly 5 tatami-free rooms of size $s = 1320$: 20×66, 22×60, 24×55, 30×44 and 33×40. In fact, $s = 1320$ is the smallest room-size $s$ for which $T(s) = 5$.
Find the smallest room-size $s$ for which $T(s) = 200$.
# --hints--
`euler256()` should return 85765680.
`tatamiFreeRooms()` should return `85765680`.
```js
assert.strictEqual(euler256(), 85765680);
assert.strictEqual(tatamiFreeRooms(), 85765680);
```
# --seed--
@ -39,12 +41,12 @@ assert.strictEqual(euler256(), 85765680);
## --seed-contents--
```js
function euler256() {
function tatamiFreeRooms() {
return true;
}
euler256();
tatamiFreeRooms();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-257-angular-bisectors
# --description--
Given is an integer sided triangle ABC with sides a ≤ b ≤ c.
Given is an integer sided triangle $ABC$ with sides $a ≤ b ≤ c$. ($AB = c$, $BC = a$ and $AC = b$).
(AB = c, BC = a and AC = b).
The angular bisectors of the triangle intersect the sides at points $E$, $F$ and $G$ (see picture below).
The angular bisectors of the triangle intersect the sides at points E, F and G (see picture below).
<img class="img-responsive center-block" alt="triangle ABC, with angular bisectors intersecting sides at the points E, F and G" src="https://cdn.freecodecamp.org/curriculum/project-euler/angular-bisectors.gif" style="background-color: white; padding: 10px;">
The segments EF, EG and FG partition the triangle ABC into four smaller triangles: AEG, BFE, CGF and EFG. It can be proven that for each of these four triangles the ratio area(ABC)/area(subtriangle) is rational. However, there exist triangles for which some or all of these ratios are integral.
The segments $EF$, $EG$ and $FG$ partition the triangle $ABC$ into four smaller triangles: $AEG$, $BFE$, $CGF$ and $EFG$. It can be proven that for each of these four triangles the ratio $\frac{\text{area}(ABC)}{\text{area}(\text{subtriangle})}$ is rational. However, there exist triangles for which some or all of these ratios are integral.
How many triangles ABC with perimeter100,000,000 exist so that the ratio area(ABC)/area(AEG) is integral?
How many triangles $ABC$ with perimeter $≤ 100\\,000\\,000$ exist so that the ratio $\frac{\text{area}(ABC)}{\text{area}(AEG)}$ is integral?
# --hints--
`euler257()` should return 139012411.
`angularBisectors()` should return `139012411`.
```js
assert.strictEqual(euler257(), 139012411);
assert.strictEqual(angularBisectors(), 139012411);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler257(), 139012411);
## --seed-contents--
```js
function euler257() {
function angularBisectors() {
return true;
}
euler257();
angularBisectors();
```
# --solutions--

View File

@ -10,14 +10,17 @@ dashedName: problem-258-a-lagged-fibonacci-sequence
A sequence is defined as:
gk = 1, for 0 ≤ k ≤ 1999 gk = gk-2000 + gk-1999, for k ≥ 2000. Find gk mod 20092010 for k = 1018.
- $g_k = 1$, for $0 ≤ k ≤ 1999$
- $g_k = g_{k - 2000} + g_{k - 1999}$, for $k ≥ 2000$.
Find $g_k$ mod 20092010 for $k = {10}^{18}$.
# --hints--
`euler258()` should return 12747994.
`laggedFibonacciSequence()` should return `12747994`.
```js
assert.strictEqual(euler258(), 12747994);
assert.strictEqual(laggedFibonacciSequence(), 12747994);
```
# --seed--
@ -25,12 +28,12 @@ assert.strictEqual(euler258(), 12747994);
## --seed-contents--
```js
function euler258() {
function laggedFibonacciSequence() {
return true;
}
euler258();
laggedFibonacciSequence();
```
# --solutions--

View File

@ -10,16 +10,23 @@ dashedName: problem-259-reachable-numbers
A positive integer will be called reachable if it can result from an arithmetic expression obeying the following rules:
Uses the digits 1 through 9, in that order and exactly once each. Any successive digits can be concatenated (for example, using the digits 2, 3 and 4 we obtain the number 234). Only the four usual binary arithmetic operations (addition, subtraction, multiplication and division) are allowed. Each operation can be used any number of times, or not at all. Unary minus is not allowed. Any number of (possibly nested) parentheses may be used to define the order of operations. For example, 42 is reachable, since (1/23) *((4*5)-6) \* (78-9) = 42.
- Uses the digits 1 through 9, in that order and exactly once each.
- Any successive digits can be concatenated (for example, using the digits 2, 3 and 4 we obtain the number 234).
- Only the four usual binary arithmetic operations (addition, subtraction, multiplication and division) are allowed.
- Each operation can be used any number of times, or not at all.
- Unary minus is not allowed.
- Any number of (possibly nested) parentheses may be used to define the order of operations.
For example, 42 is reachable, since $\frac{1}{23} \times ((4 \times 5) - 6) \times (78 - 9) = 42$.
What is the sum of all positive reachable integers?
# --hints--
`euler259()` should return 20101196798.
`reachableNumbers()` should return `20101196798`.
```js
assert.strictEqual(euler259(), 20101196798);
assert.strictEqual(reachableNumbers(), 20101196798);
```
# --seed--
@ -27,12 +34,12 @@ assert.strictEqual(euler259(), 20101196798);
## --seed-contents--
```js
function euler259() {
function reachableNumbers() {
return true;
}
euler259();
reachableNumbers();
```
# --solutions--

View File

@ -10,24 +10,34 @@ dashedName: problem-260-stone-game
A game is played with three piles of stones and two players.
At her turn, a player removes one or more stones from the piles. However, if she takes stones from more than one pile, she must remove the same number of stones from each of the selected piles.
On each player's turn, the player removes one or more stones from the piles. However, if the player takes stones from more than one pile, the same number of stunes must be removed from each of the selected piles.
In other words, the player chooses some N>0 and removes: N stones from any single pile; or N stones from each of any two piles (2N total); or N stones from each of the three piles (3N total). The player taking the last stone(s) wins the game.
In other words, the player chooses some $N > 0$ and removes:
A winning configuration is one where the first player can force a win. For example, (0,0,13), (0,11,11) and (5,5,5) are winning configurations because the first player can immediately remove all stones.
- $N$ stones from any single pile; or
- $N$ stones from each of any two piles ($2N$ total); or
- $N$ stones from each of the three piles ($3N$ total).
A losing configuration is one where the second player can force a win, no matter what the first player does. For example, (0,1,2) and (1,3,3) are losing configurations: any legal move leaves a winning configuration for the second player.
The player taking the last stone(s) wins the game.
Consider all losing configurations (xi,yi,zi) where xi ≤ yi ≤ zi ≤ 100. We can verify that Σ(xi+yi+zi) = 173895 for these.
A winning configuration is one where the first player can force a win.
Find Σ(xi+yi+zi) where (xi,yi,zi) ranges over the losing configurations with xi ≤ yi ≤ zi ≤ 1000.
For example, (0,0,13), (0,11,11) and (5,5,5) are winning configurations because the first player can immediately remove all stones.
A losing configuration is one where the second player can force a win, no matter what the first player does.
For example, (0,1,2) and (1,3,3) are losing configurations: any legal move leaves a winning configuration for the second player.
Consider all losing configurations ($x_i$,$y_i$,$z_i$) where $x_i ≤ y_i ≤ z_i ≤ 100$. We can verify that $\sum (x_i + y_i + z_i) = 173\\,895$ for these.
Find $\sum (x_i + y_i + z_i)$ where ($x_i$,$y_i$,$z_i$) ranges over the losing configurations with $x_i ≤ y_i ≤ z_i ≤ 1000$.
# --hints--
`euler260()` should return 167542057.
`stoneGame()` should return `167542057`.
```js
assert.strictEqual(euler260(), 167542057);
assert.strictEqual(stoneGame(), 167542057);
```
# --seed--
@ -35,12 +45,12 @@ assert.strictEqual(euler260(), 167542057);
## --seed-contents--
```js
function euler260() {
function stoneGame() {
return true;
}
euler260();
stoneGame();
```
# --solutions--