Skip to content

Instantly share code, notes, and snippets.

@mathildathompson
Created March 31, 2014 21:56
Show Gist options
  • Save mathildathompson/9903238 to your computer and use it in GitHub Desktop.
Save mathildathompson/9903238 to your computer and use it in GitHub Desktop.

Grains

There once was a wise servant who saved the life of a prince. The king promised to pay whatever the servant could dream up. Knowing that the king loved chess, the servant told the king he would like to have grains of wheat. One grain on the first square of a chess board. Two grains on the next. Four on the third, and so on.

There are 64 squares on a chessboard.

Write a program that shows

  • how many grains were on each square, and
  • the total number of grains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment