DEV Community

Discussion on: Daily Challenge #134 - Rice and Chessboard Problem

Collapse
 
andreasjakof profile image
Andreas Jakof • Edited

like Nick Holmes' approach, very elegant, but Log or Log2 uses double as input type, which has not enough bits, when we stick to the chess board.

Since a chessboard has 64 tiles, we would need an unsigned long (64 bit) to capture the complete number space. double has also 64 bit, but reserves some for the exponent, introducing a small, but not negligible error when coming closer to the last tiles. double precision is 15-17 digits, but we need up to 20 digits to represent such big numbers.
E.g. if you are just a few (lets say 90, to be safe - we are already in the quadrillions to give some relation) grains over the 63th tile the error would result in giving you 63 instead of 64.