2018-10-10 22:03:03 +00:00
---
id: 5900f5371000cf542c51004a
2021-02-06 04:42:36 +00:00
title: 'Problem 459: Flipping game'
2018-10-10 22:03:03 +00:00
challengeType: 5
2021-02-06 04:42:36 +00:00
forumTopicId: 302133
2021-01-13 02:31:00 +00:00
dashedName: problem-459-flipping-game
2018-10-10 22:03:03 +00:00
---
2020-12-16 07:37:30 +00:00
# --description--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
The flipping game is a two player game played on a N by N square board.
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Each square contains a disk with one side white and one side black.
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
The game starts with all disks showing their white side.
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
A turn consists of flipping all disks in a rectangle with the following properties: the upper right corner of the rectangle contains a white disk the rectangle width is a perfect square (1, 4, 9, 16, ...) the rectangle height is a triangular number (1, 3, 6, 10, ...)
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Players alternate turns. A player wins by turning the grid all black.
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Let W(N) be the number of winning moves for the first player on a N by N board with all disks white, assuming perfect play. W(1) = 1, W(2) = 0, W(5) = 8 and W(102) = 31395.
For N=5, the first player's eight winning first moves are:
Find W(106).
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
# --hints--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
`euler459()` should return 3996390106631.
2018-10-10 22:03:03 +00:00
```js
2020-12-16 07:37:30 +00:00
assert.strictEqual(euler459(), 3996390106631);
2018-10-10 22:03:03 +00:00
```
2020-08-13 15:24:35 +00:00
2021-01-13 02:31:00 +00:00
# --seed--
## --seed-contents--
```js
function euler459() {
return true;
}
euler459();
```
2020-12-16 07:37:30 +00:00
# --solutions--
2021-01-13 02:31:00 +00:00
```js
// solution required
```