7 kyu
The wheat/rice and chessboard problem
5,657 of 9,318GiacomoSorbi
Loading description...
Mathematics
Recursion
Puzzles
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Hello, I get a "Max Buffer Size Reached" error after test attempt 11m or something in Python. I am unsure how to proceed. Any help ?
avoid printing millions of characters
probably printing. try silencing the print statement.
@natan ~ your comment says 10 minutes ago, mine says 11 minutes ago, but yours is posted above mine...
¯\_(ツ)_/¯
the same exact code used to pass the kata in C# times out when applied to Java
There is an issue with your C# solution: It does not work for large input values (>= 2**62). The
amount
variable overflows for these input values.Java translation ඞඞඞඞ >>>>>>>>>>>>>>>>>>> https://www.codewars.com/kumite/67031c1f32402fbb869b0993?sel=67031c1f32402fbb869b0993
Approved
Fixed description merge problems of Clojure Translation by a deleted user.
Lua translation!
Approved
Groovy - negative random input (-727379968)
Fixed.
PHP Translation (Author inactive)
Approved
Ruby fix: move tests to Ruby 3 and RSpec (Author inactive)
Approved
JS fix: move tests to Node v18 and chai (Author inactive)
Approved
I think should delete tag "recursion". it's misleading!
One of test cases states that the input 3 must produce result of 2. This implies that the total amount of grain is summed up, i.e. the character in this puzzle receives grain/rice from all squares up to and including the last one. But other test cases clearly imply that he or she gets the amount only from the last square. This is a very sloppy kata and test cases and description have to be more clear. Or am I missing something?
Hi @rsschool_94d9c29d4afff48c ;
As this kata has the
puzzle
tag, it normally means that the description is allowed to be a bit less detailed (because, in this case, any more information will basically spoil the answer), but the test cases are correct.Maybe the wording is not 100% clear: it is asking not for the total amount of grain but rather, which square will you "reach" for a given amount of grains.
For input
3 grains
: you can place 1 grain on square 1, since first square has "capacity" of 1 grain. Then you can place 2 grains on second square since it has capacity of 2 grains.You now have
3-1-2 = 0
grains remaining so you are finished - and you have successfully placed all 3 grains and you only needed 2 squares to do this.For 4 grains, the second square is full so you need to move to the next available square (square #3) which has spare capacity. So answer for
4 grains
is3 squares
.Thank you! Superb explanation. Now it makes sense
This comment has been hidden.
I really gotta get used to feeling dumb.
Groovy: includes negative numbers. This is inconsistent with other languages.
Fixed in this fork
COBOL translation updated to new test suite.
Approved by someone
COBOL translation kumited.
Thanks :)
One brace
{
is missing in C++ initial code.added
C++ start code problem: add first "{" for function :)
Raised as an issue.
This comment has been hidden.
OP solved it, closing
Ruby 3.0 should be enabled, see this to learn how to do it
This comment has been hidden.
Agreed, I'm sick and tired of all these math problems.
Then I'm glad you're not forced to solve these kata's. Let me introduce you to the "skip" button ;-)
Random test (groovy) checks for negative numbers. Using the absolute still returns an incorrect result (expecting 32 while it's actually 30 that is correct)
C# tests seem broken, if I understood correctly the kata. Specifically this section.
Assert.AreEqual(2, Kata.SquaresNeeded(2)); Assert.AreEqual(2, Kata.SquaresNeeded(3));
2 grains should always be on the second square.
Read the description again, 1 grain of rice in the first square, 2 in the second, so, either for 2 o 3 grains of rice, you need to count until the second square. What's the issue?
Thanks for the clarification with the counting, managed to solve the problem with it.
C++ 17 should be enabled.
enabled
Typescript and Julia translations.
Grooy translation kumited. Please review and approve. Thanks, suic
Prolog translation kumited.
In the instructions: squares_needed(1) == 1
In the tests it comes back negative as 1 should equal 0 apparently.
C# Translation added.Please review and approve~
python version doesn't seem to allow importing log function from math.
It is actually used in many successful situations; what error are you getting, exactly?
ValueError: math domain error
Ah, I see. I didn't account for the case where you feed me grains==0.
New to the site: Is it more appropriate for me to acknoledge here or delete the original post?
Haskell : https://www.codewars.com/kumite/5b6db5e7b118146221000170?sel=5b6db5e7b118146221000170
Question... How does 3 pieces of grains end up with a result of 2? The second square should be 2 grains or less, no?
This comment has been hidden.
If square 2 yields 2 grains, surely you need a third square to get 3 grains. I agree with @strama4
The compensation is the sum of all grains on the board; not just the grains in the last square.
oh my god i did not interperet it this way, thank you.
This comment has been hidden.
You missed a
return
;-)oh damm indeed I did. that indeed make it work thanks :D