The wheat/rice and chessboard problem
Description:
I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests wheat, for some reason) problem, but a quick recap for you: a young man asks as a compensation only 1
grain of rice for the first square, 2
grains for the second, 4
for the third, 8
for the fourth and so on, always doubling the previous.
Your task is pretty straightforward (but not necessarily easy): given an amount of grains, you need to return up to which square of the chessboard one should count in order to get at least as many.
As usual, a few examples might be way better than thousands of words from me:
0 grains need 0 cells
1 grain needs 1 cell
2 grains need 2 cells
3 grains need 2 cells
4 grains need 3 cells
and etc.
Input is always going to be valid/reasonable: ie: a non negative number; extra cookie for not using a loop to compute square-by-square (at least not directly) and instead trying a smarter approach [hint: some peculiar operator]; a trick converting the number might also work: impress me!
Similar Kata:
Stats:
Created | May 29, 2018 |
Published | May 29, 2018 |
Warriors Trained | 15703 |
Total Skips | 223 |
Total Code Submissions | 28104 |
Total Times Completed | 9317 |
JavaScript Completions | 5657 |
C++ Completions | 611 |
Ruby Completions | 147 |
Python Completions | 2153 |
Crystal Completions | 18 |
Haskell Completions | 120 |
C# Completions | 383 |
C Completions | 208 |
Prolog Completions | 20 |
Groovy Completions | 27 |
TypeScript Completions | 149 |
Julia Completions | 29 |
COBOL Completions | 8 |
PHP Completions | 74 |
Dart Completions | 14 |
Lua Completions | 12 |
Java Completions | 111 |
Total Stars | 178 |
% of votes with a positive feedback rating | 89% of 1070 |
Total "Very Satisfied" Votes | 880 |
Total "Somewhat Satisfied" Votes | 139 |
Total "Not Satisfied" Votes | 51 |
Total Rank Assessments | 6 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |