5 kyu
Find heavy ball - level: master
776 of 1,741tiriana
Loading description...
Puzzles
Logic
Riddles
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.
C translation (author inactive)
Approved
OCaml translation.
Please review and approve, thanks !
approved
Ruby 3.0 should be enabled.
I tried to exploit the life attribute of the object and it worked for the practice cases. How did you remove it for the tests
Ruby, Crystal and c++ translations kumited :)
@tiriana
,This kata isn't compatible with Python 3 because of
xrange
.Fixed. Thanks for reporting.
Why are there 200 test cases when there are only 8 possible cases?
expecting the n-ball kata
Python version kumited. Took some measure in case of cheating. :)
I cannot see translation to this version - I approved translation for novice, but I can't see rest...
Strange... I did post it and I can see it myself. Anything wrong with codewars?
Maybe it's just me being lost. How do you navigate to those kumites?
And btw, some guy reported as issue, I suppouse it's connected with python version, but I'm not python export. Could you take a look? - http://www.codewars.com/kata/find-heavy-ball-level-novice/discuss#56aa22a4e79a7b86ac000077
Ok, I found it (the translation - not solutuion for the issue :) )
BTW. You may be interested in translating this kata: http://www.codewars.com/kata/find-heavy-ball-level-ubermaster
Alright thx. I will take a look at that :)
This comment has been hidden.
Ok... So what should I Do? :-)
I don't exactly know... Perhaps you may take a look at kumite and see if there is any UI to approved the newer version of description..
ubermaster version translated to python :) thanks for guiding me there
I don's see this. I republished all three katas, but there were no changes, so I doubt it would help. But you can try now to update the description and we'll see.
If that does not work than next thing we can do is: I can delete current python translation, and you could upload updated version again. I know, I know - ugly as hell, but might work.
If that does not do the trick - we can ask jhoffner
I forked it and updated changes. You may get the newer one approved.
Done
Had fun with three katas of this series. :)
Too simple for 5kyu IMO :)
This kata was ranked awhile ago when people ranked by refering to the description than how fast or easy they found it, some concepts come naturally to people. In saying that I do agree that this kata could be ranked to maybe a 6 at the most.
It's simple when you see it, but before that it's quite mysterious :)
The getWeight instance method does not break after two uses. Perhaps you should include a
@scale_used
to keep track of the number of uses. It should only be a couple of lines of code.The getWeight instance method only takes Array as arguments, but your example code passes in Number/FixNum. This is very misleading. Either modify the method to coerce the value or change your example code.
Do you mean the ruby translation? I admit - I approved it to fast, tests weren't taking 'time to live' into consideration at all. Sorry for that. I disabled this translation as a quick fix.
This puzzle is sort of well known. Since the solution to find the heavier ball out of n-th is readily available, this should be 6 or 7 kyu.
Or you can try to make it more difficult by having one ball differ in weight but let the coder find out which ball and which direction (heavier/lighter).
Loved it! Very nice logical puzzle - hard to get at first but very easy to code when you 'get it'.
Hi.
Why the instructions says you can use the scale twice but a commentary in code says that you can use max 4 times?
Thanks for your answer.
typo. I changed that, thx.
How did this get thru beta? This is the worst Kata I've seen. Clear up the instructions! I solved this but there's no clear instructions for how the solution should be implemented. Where does the 8 element array of numbers come from? What should the method return?
I wish there was a way to down vote.
Hello :)
I must say that 'This is the worst Kata I've seen' made my day :) I admit - the instructions could have been more clear, but to call it 'the worst'? :) I LOLed hard, thanks for that.
I changed the description - please let me know if it's better now.
You should probably add an example of how .getWeight() method is used. Like this:
MMMAAANNN, that helps.
I simply want to know the method signature, including the expected result.
For example:
findBall(arrayOfBalls) { // call scales.getWeight() only twice return indexOfHeavyBall; }
In addition, I think adding a couple example unit tests would help the most. At least then we know what the method accepts as parameters and what to expect as output.
tiriana, your spelling errors should also be corrected.
"Your function - findBall will receive single argument - scales object. ----> I has only one method <----"
You sound like you're speaking Engrish. I suggest finding someone who speaks English to proofread for you.
You should also define what a "single argument" is exactly. Is it an array of integer values representing ball weights? If so, say that! Please avoid ambiguity. This isn't an in-person interview where we are able to ask you clarifying questions, so you need to be clear from the start.
This comment has been hidden.
@MMMAAANNN Great idea - thx for that, I will add it to description.
May I suggest something like this:
Your function - findBall will receive single argument - scales object. The scales object contains an internally stored array of 8 elements (indexes 0-7), each having the same value except one, which is greater. It also has a public method named getWeight(left, right) which takes two arrays of indexes and returns -1, 0, or 1 based on the accumulation of the values found at the indexes passed are heavier, equal, or lighter.
Your job is to write a method - findBall(scales) which will take the scales object and call its getWeight() method only twice to determine which index of the internal array has a greater weight.
@tiriana, consider using Preloaded section to define something but hide it from user. Maybe it can help designing example test cases (I'm not sure if it actually helps, I just wanted to highlight the possibility).
I feel it would be beneficial to add "function" in front of "findBall(scales) {", though, this is 5 kyu, :) people should know they have to add it.
the initial cod needs "function" in front of "findBall(scales) {"
otherwise, i think you got it. thx
@cforsyth68 I added
function
, thanks. I also used description you sent - thanks for that too.Is it possible to get some testcases written for this. The Kata is completely unclear as to where the array datastructures are coming from given that we're supposed to be manipulating them. It's a nice riddle though.
nm
The instructions don't say what the function is supposed to return. I assumed it wanted the index of the ball and I was right but it should say that.
Loved these tests. Good job!
Thanks a lot :)
Perhaps make default code for the students to test with. This would make it clear how to use the scale input parameter.
Thanks for feedback. I changed scale object. I used the previous one as prototype, so all for backwards compatibility. Now scale has only one moethod -
getWeight(left, right)
. I also added some description about how to use the scale. I'm marking as resolved.Really good riddle. Thanks for putting it up as a kata.
I'm glad you like it :)
This is one of those kata that the difficulty is difficult to rate. On the one hand, the programming required to solve it, once you know how, is trivial. On the other hand, solving the problem is quite difficult (if you don't know it already). I just don't know...
That's fine, I feel the same about this kata. When my colegue ask me this question few days ago it took me quite a while to figure it out. But after I did - it seems just super obviuos.
Community will decide how to rate this one :)
Typo in tests:
Should be 'right'.
Thx - fixed.
Now I see I only changed message. I will change
leftPan.join();
torightPan.join();
as wellFixed in message and code.
I have no clue how to do it in Twice scales.getWeight() calling. Please help me.
@brooke_b What have you tried so far?