5 kyu
Find heavy ball - level: ubermaster
422 of 603bellmyer
Loading description...
Algorithms
Logic
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.
What's the point if one solution could do for the entire series?
I'm a little confused - what is the datatype of the ball_count object? the description makes it sound like its simply an integer, representing the number of balls to be tested. how is the data for ball weights and indices handled?
It is a number.
CoffeeScript translation
This comment has been hidden.
[JavaScript] Naming convention is inconsistent - the user solution is named
findBall
which is camelCase while the second argumentball_count
is in snake_case. Please changeball_count
toballCount
so everything is in camelCase (source: W3Schools).done
please review and aprove, thx xD
??
Python translation has sample test being
test.assert_equals(1 + 1, 2)
instead of actual testsduplicate issue
There is no mathematical reason to restrict the lower bound of balls count to
8
, it should be1
.C translation (author inactive)
OCaml translation.
Please review and approve, thanks !
approved
C++ translation in need of approval
Knowing the logic is not a problem if you have finished the previous kata It is quite tricky to deal with edge cases in this kata. Always get the wrong answer for a few random tests before I modify my solution Nice kata :)
Ruby translation
why here isn't available Cpp as in previous katas? :(
Cuz Cpp heroes are so busy :)
here is C++ translation
No sample tests.
Out of curiosity, why cap the maximum number of balls to 500?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I really like this Kata. Excellent job.
I dont understand how to write the Test Driven Development of this problem. Thanks!
For Python: I am having difficulty creating my own test cases as suggested because I do not know how to create a 'scales' object. Do I need to import something from somewhere? What arguments are used to create the examples I would like to test with? Thanks.
This comment has been hidden.
In the worst case with 170 balls, your solution actually needs 6 uses of the scale.
Hint: see what happens in your solution if the last ball is heaviest
Ok thanks, checking my solution now
This comment has been hidden.
For the Python version:
3.4: 'NameError: name 'xrange' is not defined'. You should use 'range' instead. 2.7: Though the instructions state that the method is getWeight, it's actually get_weight.
Otherwise, good kata! Thanks!
xrange: Somebody else previously fixed it. getWeight: I've just fixed it.
If we get a "Scale is broken" result, does that mean the scale use exceeds the alloted times for the specified amount?
Yes.
python kumited :)
You should use
range
instead ofxrange
to allow Python 3 version to work.Because testing is left to the user, details on how to set up a test 'scales' object should be provided. In my case I had to go to the novice/conqueror/master versions of this kata to steal test code.
Agreed!
raised as an issue : no sample tests
This comment has been hidden.
I'm not enough of an expert to answer your question, but would like to mention that it is possible (though not necessarily better) to solve this without using switch or if statements.
Hi, nice kata, but I'm pretty sure there's a bug in your current test, such that some calls to
scale.getWeight(A,B)
wrongly return -1 instead of 1 when the heavy ball is in the right-hand pan (B). I see it when Iconsole.log()
the balls being weighed and the outcome, then compare it to the test answer.If this was so, nobody would ever pass this kata. Can you post your solution here with the spoiler tag?
Thanks for quick reply. Yeah, you're right, of course; I figured it out. I'd written tests I thought were independently validating my solution, but they shared the same flaw.
Nice one, I'm glad you generalized my katas :)
I added link to this kata in one of mine
I would just like to ask you to add an anotation at the bottom of your description that your kata is based on mine, with a link to my profile.
I've not yet done this kata, but in the description it says: "(ball count) 0-9 | (uses) 2". Shouldn't it be "1 | 0", "2-3 | 1" and "4-9 | 2"?
And also: Although perfectly legal, why start with 8 balls? Why not have the entire span of 0 to 500 instead? Seems somewhat arbitrary to pick 8 as the starting number.
I think the "So where's the catch" line could use some work. You should explain that the number of balls will be different each time, reaching up to five hundred, and your task is to return the correct ball in the minimum number of weighings. The way you explain it currently is just confusing, even to someone (such as myself) who has completed the other katas in this series.
You're right. For continuity's sake, I was trying to preserve as much of the previous kata descriptions as possible. I reworked the "catch" portion, per your suggestion. Thanks!
Yeah, that works well now.
Another very minor gripe is that there are no easier tests to pass before going through the randomly-generated ones. It's just a little tricky to debug stuff when you never get the same test twice, and it's kind of impossible to write your own tests as-is. So I was wondering if you could add some to the test fixture, or have a couple of fixed tests at the beginning (a small count and a large count) to get you started down the right path, before blasting us with the randoms.
Yeah, that bothered me about the first three levels as well. I'll see what I can do.
In the prefilled code, the findBall method has only one argument, scales, where it should also have the count argument.
Thanks, this is fixed now!