Confused101's blog

By Confused101, history, 8 years ago, In English

Numbers 1....N are written in table (3 <= N <= 1000), at each step one player choose some number and mark it as visited, player wins if he can make 3 consecutive numbers visited in his turn. Who will win the game if both play optimally? game is 2-player game with alternating turns.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it +4 Vote: I do not like it

It's obvious that if we mark some number x, an opponent instantly loses if he takes any number y : |x - y| ≤ 2.

Let's define f(n) the answer for table of "length" n. We know that f(3) = 1 (1st player wins on such board anyways). Trying all possible moves we can easily calculate f(n): by taking some number x (1 ≤ x ≤ n), we split the table into two parts of lengths max(0, x - 3) and max(0, n - x - 2), since there's no point of keeping neighbouring to x unavailable numbers on the table.

If you still have some difficulties, googling "sprague grundy theory" shuold help.