Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

Nim

Play Nim: take counters from one row at a time. Normal or misere rules, optional take limit, and a perfect computer you can learn to beat.

How to play

  1. There are rows of counters. On your turn take one or more counters, all from the same row.
  2. Tap the first counter you want to take: it and every counter to its right are marked. Then press Take.
  3. Normal rule: whoever takes the last counter wins. Misere rule: whoever takes the last counter loses.
  4. With a take limit you may take only 1 or 2 (or 1 to 3) counters at a time.
  5. The perfect computer cannot be beaten from a winning start, but it can be beaten from a losing one: learn the trick and choose who moves first wisely.

Keyboard and touch

TabMove between the buttons
Enter or SpacePress the focused button
TapTap a button

Tips

  • Write each row's size in binary and add the columns without carrying (exclusive or): that is the nim-sum. Leave your opponent a nim-sum of 0 and you will win.
  • With a take limit of k, use each row's remainder after dividing by k + 1 instead of the row size.
  • Misere play works exactly like normal play until only rows of 1 counter would be left: then leave an odd number of single counters.
  • Press Show the winning move to see the right move, and tick Show the nim-sum to watch the number.

About this game

Nim is an ancient counter game and the starting point of combinatorial game theory: Charles Bouton worked out the complete winning strategy in 1901. Our perfect computer uses the nim-sum (and an exact search for misere play with a take limit). The tests compare every winning move against an independent exhaustive search of the game tree on thousands of positions. Everything runs in your browser.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product