fix(curriculum): rework Project Euler 100 (#42313)
* fix: rework challenge to use argument in function * fix: add solution * fix: use MathJax to improve look of math notation * fix: corrections from review Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>
This commit is contained in:
@ -8,24 +8,50 @@ dashedName: problem-100-arranged-probability
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, P(BB) = (15/21)×(14/20) = 1/2.
|
If a box contains twenty-one colored discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs.
|
||||||
|
|
||||||
The next such arrangement, for which there is exactly 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.
|
$${P(BB)} = \frac{15}{21}×\frac{14}{20} = \frac{1}{2}$$
|
||||||
|
|
||||||
By finding the first arrangement to contain over 10<sup>12</sup> = 1,000,000,000,000 discs in total, determine the number of blue discs that the box would contain.
|
The next such arrangement, for which there is exactly a 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.
|
||||||
|
|
||||||
|
By finding the first arrangement to contain over `limit` discs in total, determine the number of blue discs that the box would contain.
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`arrangedProbability()` should return a number.
|
`arrangedProbability(20)` should return a number.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof arrangedProbability() === 'number');
|
assert(typeof arrangedProbability(10) === 'number');
|
||||||
```
|
```
|
||||||
|
|
||||||
`arrangedProbability()` should return 756872327473.
|
`arrangedProbability(20)` should return `15`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(arrangedProbability(), 756872327473);
|
assert.strictEqual(arrangedProbability(20), 15);
|
||||||
|
```
|
||||||
|
|
||||||
|
`arrangedProbability(100)` should return `85`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.strictEqual(arrangedProbability(100), 85);
|
||||||
|
```
|
||||||
|
|
||||||
|
`arrangedProbability(100000)` should return `97513`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.strictEqual(arrangedProbability(100000), 97513);
|
||||||
|
```
|
||||||
|
|
||||||
|
`arrangedProbability(1000000000)` should return `3822685023`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.strictEqual(arrangedProbability(1000000000), 3822685023);
|
||||||
|
```
|
||||||
|
|
||||||
|
`arrangedProbability(1000000000000)` should return `756872327473`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.strictEqual(arrangedProbability(1000000000000), 756872327473);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -33,16 +59,29 @@ assert.strictEqual(arrangedProbability(), 756872327473);
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function arrangedProbability() {
|
function arrangedProbability(limit) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
arrangedProbability();
|
arrangedProbability(20);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function arrangedProbability(limit) {
|
||||||
|
// Based on https://www.mathblog.dk/project-euler-100-blue-discs-two-blue/
|
||||||
|
let blue = 15;
|
||||||
|
let discs = 21;
|
||||||
|
|
||||||
|
while (discs < limit) {
|
||||||
|
const nextBlue = 3 * blue + 2 * discs - 2;
|
||||||
|
const nextDiscs = 4 * blue + 3 * discs - 3;
|
||||||
|
|
||||||
|
blue = nextBlue;
|
||||||
|
discs = nextDiscs;
|
||||||
|
}
|
||||||
|
return blue;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user