diff --git a/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-100-arranged-probability.md b/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-100-arranged-probability.md index 7a5d2fd453..1d44675e28 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-100-arranged-probability.md +++ b/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-100-arranged-probability.md @@ -8,24 +8,50 @@ dashedName: problem-100-arranged-probability # --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 1012 = 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-- -`arrangedProbability()` should return a number. +`arrangedProbability(20)` should return a number. ```js -assert(typeof arrangedProbability() === 'number'); +assert(typeof arrangedProbability(10) === 'number'); ``` -`arrangedProbability()` should return 756872327473. +`arrangedProbability(20)` should return `15`. ```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-- @@ -33,16 +59,29 @@ assert.strictEqual(arrangedProbability(), 756872327473); ## --seed-contents-- ```js -function arrangedProbability() { +function arrangedProbability(limit) { return true; } -arrangedProbability(); +arrangedProbability(20); ``` # --solutions-- ```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; +} ```