yaworsw/euler-manager

View on GitHub
data/problems/301.yml

Summary

Maintainability
Test Coverage
---
:id: 301
:name: Nim
:url: https://projecteuler.net/problem=301
:content: "_Nim_ is a game played with heaps of stones, where two players take it
  in turn to remove any number of stones from any heap until no stones remain.\n\nWe'll
  consider the three-heap normal-play version of Nim, which works as follows:  \n-
  At the start of the game there are three heaps of stones.  \n- On his turn the player
  removes any positive number of stones from any single heap.  \n- The first player
  unable to move (because no stones remain) loses.\n\nIf (<var>n</var><sub>1</sub>,<var>n</var><sub>2</sub>,<var>n</var><sub>3</sub>)
  indicates a Nim position consisting of heaps of size <var>n</var><sub>1</sub>, <var>n</var><sub>2</sub>
  and <var>n</var><sub>3</sub> then there is a simple function <var>X</var>(<var>n</var><sub>1</sub>,<var>n</var><sub>2</sub>,<var>n</var><sub>3</sub>)
  — that you may look up or attempt to deduce for yourself — that returns:\n\n- zero
  if, with perfect strategy, the player about to move will eventually lose; or\n-
  non-zero if, with perfect strategy, the player about to move will eventually win.\n\nFor
  example <var>X</var>(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:  \n- current player moves
  to (1,2,1)  \n- opponent moves to (1,0,1)  \n- current player moves to (0,0,1)  \n-
  opponent moves to (0,0,0), and so wins.\n\nFor how many positive integers <var>n</var> ≤ 2<sup>30</sup>
  does <var>X</var>(<var>n</var>,2<var>n</var>,3<var>n</var>) = 0 ?\n\n"