Last active
July 18, 2026 20:17
-
-
Save jonesor/3141b31cc5f3920b4830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rice on a chessboard: 1 grain on the first square, doubling each square. | |
| # Vectorised: square i holds 2^(i-1) grains. | |
| RiceOnASquare <- 2^(0:63) | |
| sum(RiceOnASquare) | |
| # NOTE: the true total is 2^64 - 1 = 18,446,744,073,709,551,615, which exceeds | |
| # R's exact double-precision integer range (2^53). For the exact value use gmp: | |
| # library(gmp); sum(as.bigz(2)^(0:63)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment