5 kyu
Equivalent Dice
106 of 148raulbc777
Loading description...
Algorithms
Performance
Number Theory
Recursion
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.
This comment has been hidden.
python new test framework
Approved!
Has anyone solved this in Javascript lately?
I keep failing 5-6 random tests, even though I produce the same result as in the Python version (which passes all tests)
For input:
[ 11, 11, 4, 12, 11, 5, 4 ]
, Python produces 15 but the JS version requires 16.For input:
[ 9, 8, 7, 11, 5, 6, 7 ]
, Python produces 58 but the JS version requires 72.Are there problems in the JS version, or are the tests in Python somewhat lax?
I tested 3 JS solutions. They all work. One test case sometimes fails {5,4}, but that one is known to fail (see comment section).
Two of the "random" test cases are wrong.
It works for smaller cases and larger cases. I think it only breaks on
20
.It's true. Simply add this case to pass kata :))
same in Ruby with
[4,5]
expecting 1 instead of 0Am I missing something? The test cases list [3, 3] as having no equivalent dice paterns, but wouldn't [9] also have 9 outcomes?
Are we only allowed solution sets with 2 or more dice? Speaking of, I can solve this puzzle pretty easily for equivalent sets of two or three or any definite number, but I'm having trouble coming up with a solution for writing a recursive algorithm when the number of dice is undefined. Can anyone provide help on resources for how to write a recursive algorithm for this sort of thing? Probably too vague a question.
Yes, as stated here:
Haskell translation
approved by someone.
( JS )
From a random test:
eqDice( [ 4, 4, 5, 5 ] ) => 5
But I can only find equivalent sets
[ 4, 5, 20 ], [ 4, 10, 10 ], [ 5, 5, 16 ], [ 5, 8, 10 ] ]
. What is the fifth?I have the same problem with
eqDice([3,8,15,20]) => 44
from the basic tests, where I can only find 42, but that's a bit unwieldy to post.The set itself is not supposed to count as an equivalent set, right?
Hi Johan. The answer to your questions:
And for the basic test:
As you don't count the given set itself the result the result is
length - 1
Ah, I forgot
[20,20]
. Bug in my solution.Now I'm running into
eqDice([4,5]) => 1
. Surely this should be0
?Yes, it should be 0. In python 3 it gives the correct result. With this observation you helped to discover a bug in Ruby and javascript version. I'll fix it in some minutes.
I am running the Ruby version of this and I think there might be an issue with a test. My code passes all test except the [4,5] one. Which says "excepted 1 got 0):
Log {"4,5"=>1} Expected: 1, instead got: 0
However, we are talking about 20 as the value to arrive to... and according to a different test, [20] there should be only 1 combination: [4,5].
So following the logic of other tests: Total Combinations - Original Combination (IF it is valid, as [20] is not valid). [4,5] should be 0 and not 1.
Thanks for your time solving the kata and being the first one in solving it in the ruby version. I changed the test
[6]
for this one:[3,3]
, a valid one that has length higher than1
and, of course, with result0
.I think the reference solution somehow bugs on
[4,5]
.You've never flipped a coin ?!?
I've done that a lot more than roll my d4 with one empty side ( which I don't have - I'd use a d6 div 2 or mod 3 ( and if I get away with it, I decide afterwards :) ).
Hi Johan. Well, this kata is based on real games that use different regular polyhedral dice like the image below.
The behaviour of them is that all of them can be rolled easily at a time. There are some games that use some irregular polyhedral forms that have similar behaviour. With an empty face you may have covered all amount of sides in the interval [3,20].
The test cases could use some more examples.
Hi, HugoO. I'd accept it like a suggestion. What do you think?
Are you interested in some edge cases?
Not clear what is "more examples". Please raise a more detailed issue.
There is A LOT of variation in the performances requirmement from on batch to the other. My solution (forked one) can take from 0,9s to 10s to pass the tests... :/
ok, I sought for drawbacks in my solution and found some new optimizations to do. My code has now timings that are consistent. Your solution, on the other side, can still show some losses of performances on some inputs.
That means that, currently, suboptimal soluitons can pass. Maybe you should strenghten the things a little bit more?
This comment has been hidden.
Hi Raul,
If you plan on making this one harder, you should either do wuickly the modifications or unpublish it for now. Otherwise, the final rank could be inconsistent with what my be the actual task, don't you think? Or do you prefere to let it like that?
This comment has been hidden.
Well, the problem is: my solution to your kata would give up the solution to the other one. ;)
What if I suggest to you a new test suite? ok with that?
What do you think about a purple one? You've got to find the equivalent dice sets like this one and additional you select between them, the set with highest dice sum value with the highest probability? :)
errrr, you mean, one you will do?
I talked about suggesting a test suite to update the current kata. Not sure we are following each others! x)
This comment has been hidden.
ok, I'll give it some thoughts...
In random tests. Why you put .it under .assert_equals?
This comment has been hidden.
no, the problem is that doing so, the title/test.it header do not wrap the correct test:
So this is actually the worst thing you could do ;) The
test.it/describe
has to always be before the related assertion.cheers!
I see. Corrected now.