fix(curriculum): clean-up Project Euler 301-320 (#42926)
* fix: clean-up Project Euler 301-320 * 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:
@ -12,25 +12,30 @@ Nim is a game played with heaps of stones, where two players take it in turn to
|
||||
|
||||
We'll consider the three-heap normal-play version of Nim, which works as follows:
|
||||
|
||||
- At the start of the game there are three heaps of stones.
|
||||
- On his turn the player removes any positive number of stones from any single heap.
|
||||
- The first player unable to move (because no stones remain) loses.
|
||||
- At the start of the game there are three heaps of stones.
|
||||
- On his turn the player removes any positive number of stones from any single heap.
|
||||
- The first player unable to move (because no stones remain) loses.
|
||||
|
||||
If (n1,n2,n3) indicates a Nim position consisting of heaps of size n1, n2 and n3 then there is a simple function X(n1,n2,n3) — that you may look up or attempt to deduce for yourself — that returns: zero if, with perfect strategy, the player about to move will eventually lose; or non-zero if, with perfect strategy, the player about to move will eventually win. For example X(1,2,3) = 0 because, no matter what the current player does, his opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by his opponent until no stones remain; so the current player loses. To illustrate:
|
||||
If ($n_1$, $n_2$, $n_3$) indicates a Nim position consisting of heaps of size $n_1$, $n_2$ and $n_3$ then there is a simple function $X(n_1,n_2,n_3)$ — that you may look up or attempt to deduce for yourself — that returns:
|
||||
|
||||
- current player moves to (1,2,1)
|
||||
- opponent moves to (1,0,1)
|
||||
- current player moves to (0,0,1)
|
||||
- opponent moves to (0,0,0), and so wins.
|
||||
- zero if, with perfect strategy, the player about to move will eventually lose; or
|
||||
- non-zero if, with perfect strategy, the player about to move will eventually win.
|
||||
|
||||
For how many positive integers n ≤ 230 does X(n,2n,3n) = 0 ?
|
||||
For example $X(1, 2, 3) = 0$ because, no matter what the current player does, his opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by his opponent until no stones remain; so the current player loses. To illustrate:
|
||||
|
||||
- current player moves to (1,2,1)
|
||||
- opponent moves to (1,0,1)
|
||||
- current player moves to (0,0,1)
|
||||
- opponent moves to (0,0,0), and so wins.
|
||||
|
||||
For how many positive integers $n ≤ 2^{30}$ does $X(n, 2n, 3n) = 0$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler301()` should return 2178309.
|
||||
`nim()` should return `2178309`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler301(), 2178309);
|
||||
assert.strictEqual(nim(), 2178309);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -38,12 +43,12 @@ assert.strictEqual(euler301(), 2178309);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler301() {
|
||||
function nim() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler301();
|
||||
nim();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
Reference in New Issue
Block a user