6 kyu
Number of measurements to spot the counterfeit coin
258 of 1,302GiacomoSorbi
Loading description...
Logic
Fundamentals
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.
python new test framework is required. updated in this fork
Approved
In VS, my results for 8858899 are 15. Here for some reason it gives 18. Even though 15 is the correct answer.
no parameter type in the initial solution in C
Rust: incorrect function name in the initial solution. (Also,
u16
?..u32
is usually used in the standard library,u8
is enough here, so whyu16
of all types?)I chose
u16
in order not to give too much hints to the users about the magnitude of the input... Should I change it?The name is fixed in this new fork: https://www.codewars.com/kumite/62837c7f84bbe5004a739ad6?sel=62840b1d84bbe5000e73af6a
IDK about
u16
, but the standard library usesu32
in cases like https://doc.rust-lang.org/std/primitive.u64.html#associatedconstant.BITS.Changed to u32 there: https://www.codewars.com/kumite/62840b1d84bbe5000e73af6a?sel=62841204158dadcec2a2fbe0
approved
COBOL translation.
Ruby 3.0 should be enabled.
Enabled in this fork
This comment has been hidden.
This comment has been hidden.
And the point of them would be...?
https://www.codewars.com/kumite/5de4037a2fef1d00198413c9?sel=5de428aaddc2950032ea904c
You described problem better then me.
That is no longer the reference solution. But anyway thanks: running your code on the actual solution I spotted a few bigger numbers (nothing with
i > 18
is ever tested, anyway) that were failing; fixed now.P.S.: the solution for
9
was already correct.This comment has been hidden.
This comment has been hidden.
Hello!
In JavaScript: When in random test we have 9 as a parameter - test fails. It happens even in best solution (and in its variations) .
Testing for 9 - Expected: 2, instead got: 3
I think it is because of JavaScript bag: 2.0000000000000004 becomes 3
I think it is because 2 measurements are actually enough.
Read my post of 1 year ago, at some point the expected answer was 3, but the right expected answer is (and should be, it's been fixed) 2. Sometimes invalid solutions aren't marked as that when you change the tests.
The test for 9 still expects a return of 3 in JavaScript instead of 2. Based on these comments I assumed this had been fixed, but it doesn't appear so. Is this solvable in JavaScript at this point?
Randomly.
@Giacomo take a look at it again, it is as jake-utk says, the reference solution expects wrong results.
Mh, it looks like it did not take a fix I did a while ago.
Resubmitted now.
hello, Is it normal, I've got this response:
Response received but no data was written to STDOUT or STDERR
https://www.codewars.com/kata/reviews/59530d2f01d6039f86000021/groups/5dc0afd11318910001b936cf#5dc0b536c4c331002de1d9d7
Suggestions?
This solution has been invalidated by current test cases, closing
C# = > tests/Fixture.cs(24,78): error CS1503: Argument 1: cannot convert from 'long' to 'int'
Fixed, I guess?
nope, same exception: tests/Fixture.cs(24,78): error CS1503: Argument 1: cannot convert from 'long' to 'int'
Looks good to me.
Sample test works fine. My code shouldn't have impact on test failures (exception thrown)?
public static long HowManyMeasurements(long n)
The lastest function signature maybe right.Check your code again~C#:
tests/Fixture.cs(24,78): error CS1503: Argument 1: cannot convert from 'long' to 'int'
I have make a fix for it.Please waiting approve.
Fixed.
Can you kindly check above, as a problem might still be persisting?
C# Translation added.Please review and approve~
See above.
I'm Sorry for the mistake.This is a fix,please approve it: https://www.codewars.com/kumite/5dbf06020f3634001737425d?sel=5dbf85dd97af7c001776e5d6
great Kata as always, thanks!
Thank you for your feed :)
NASM translation. Please review and approve.
This comment has been hidden.
This comment has been hidden.
That's what I thought, but the tests expect 3 if I'm not mistaken (at least in javascript).
Sure: rounding problem in JS; fixed now :+1:
It still requires 3 in Ruby, so this still needs fixing in that language.
Fixed, thanks.
My solution either passes all of the tests but doesn't register as a working solution, or passes all the tests except one yet the log shows all correct solutions. Am I doing something wrong?
Language, number of attempts and possibly solution in spoiler tag?
Language is C, and I've spammed the 'attempt' button repeatedly. I'll post the solution after trying to mess around with it some more.
Ahh, disregard. The log eventually showed what my solution was failing on. Now do I include a specific edge case or try and figure this out some more. :P
Wonderful, thank you -- that really put a smile on my face :)
Glad you appreciated :)
This comment has been hidden.
You need only 2 measurements to find the fake coin among 8 :)
Please tell more. What we weigh the first time? and the second?
This is the key ;-)
Thanks. Difficulties of translation
How many coins can be weighted at one time? I think this is an important step. If you have an odd number, 79, the optimal solution would be 1 as you can measure 38 against 38, and if they are even, than the outlier is obviously the culprit in this case. I think it should be explicitly stated that only one coin can be measured against the other, or whatever the number might be.
Re-read the description:
Meaning a stable mode to assess that
79
or any other number of coins every single time with the minimum amount of weighings. Clearer :)?Yes, that helps!
Cool, glad of having been of some help :)
This comment has been hidden.
25
was apparently the expected solution, not the number of coins.This comment has been hidden.
Not really: actually dumb (and apparently popular) interview question I read around.
This comment has been hidden.
Nope, you're not doing it optimally. Try harder :)
This comment has been hidden.
You can only use two pans of a scale at once, yes, but...
Approved
I think we can file an issue by now, that we have already exposed the kata author's logic...
...
...
The kata intends to solve the problem where the counterfeit coin is known to be either heavier or lighter than the rest, but the problem is not stated as so. Instead, it states a variant of the problem, where the counterfeit coin has a different weight which we don't know whether it's heavier or lighter than the rest.
3 coins, a,b,c. a=1 b=any value != 1 c=1 we need two times to weigh(worst case):
And, what's important is: What's the worst case? The authors did not specify weighing methods ;-) For example: There are 6 coins(a,b,c,d,e,f), The worst case could be:
Fake is lighter: fixed, thanks :)
The odd one may be less weight than the other or it may be heavier than the rest 7 coins.
If we don't know whether the odd one is heavier than an ordinary coin or lighter than an ordinary coin, we can't tell if there are only two coins.Test.assertEquals(howManyMeasurements(2),1);
is a odd testcase ;-)Good catch, fixed :+1:
How is it possible in 1? One coin vs one coin, if they are different then we still don't know which one is counterfeight.
This comment has been hidden.
This comment has been hidden.
Nice
This comment has been hidden.
Added spoiler tag to avoid any extra help, but, anyway, it does not look like my kata is a copy of that, does it?