7 kyu
Determine if the poker hand is flush
2,661 of 6,271CodingWarrior
Loading description...
Arrays
Algorithms
Logic
Strings
Games
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.
Java:
camelCase
, notPascalCase
Refer here on how to enable backward compatability to not invalidate all solutions
CoffeeScript translation
python new test framework
Approved
This comment has been hidden.
Couldn't recreate.
fun kata! thank you!
Update to Scala 3
.
This comment has been hidden.
This comment has been hidden.
Ruby 3.0 should be enabled, see this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Enabled in this fork
This comment has been hidden.
You can't compare strings in Java with
==
and!=
. Usestring1.equals(string2)
.Thanks!
Scala translation kumited. Please review and approve. Regards, suic
Approved
JavaScript translation
.
( Haskell )
quickCheck
does not work; it tests but never fails; see here. It's a CodeWars bug or something; lots of customisations for QuickCheck just don't work.If you want to set
maxSuccess
,import Test.Hspec.QuickCheck
and usemodifyMaxSuccess (const 1000) $ it "random tests" $ property $
It seems like there is a significant change in the way quickcheck works because a lot of what I was doing and was working no longer does anything (verbose, maxsuccesses, etc. ).
I've never seen those things working. It's been this way on here since I started creating Haskell kata, a year or so ago.
.
Haskell : https://www.codewars.com/kumite/5b75f90569826cc1440000da?sel=5b75f90569826cc1440000da
Note, I turned collect on to ensure I was generating actual random true Flush cases.
Approved
Needs fixed test
isFlush (["10D", "4D", "QD", "KD", "5D"]) `shouldBe` True
: a flush with a10
in first place.Also, your random generator could be better. It relies on chance to generate a flush.
And you're tripping over a CodeWars thing with
quickCheck
. But that's a real issue.Added.
And yes I agree, I increased the runs to ensure they would be generated. But I do have a bookmark on figuring out how to updated that to frequency generate actual flushes (it also will generate non-possible hands, i.e. duplicates). I don't think either of those actually change the solutions generally though.
I am not sure what you mean, but it was the way quickCheck was being involked, I just fixed that as it was working with the given syntax, but isn't now so I rolled it back to using stdArgs.
oneof
take 5 <$> shuffle [either a full deck or a stack of a single colour]
Actually, it will make a difference. Because that fixed tests flushes out a bug in one of the solutions, and it has a much too small chance of being randomly generated. You don't just need to generate more flushes; you need to generate flushes with tens in different places. ( And non-flushes with tens in different places. )
I mean it doesn't test. It always succeeds.
And
quickCheck
withstdArgs
doesn't test either.You really need
Test.Hspec.QuickCheck.modifyMaxSuccess
, as I wrote in the issue ( see above ).Please really test your testing code, with a solution that should pass but also with one that should fail.
I'm not seeing that fixed test having been added BTW.
I'm still not seeing any updates to the testing. Are you sure that was published?
Johan, take a look now.
I rewrote the random test completely, it now will generate flush's frequently, and will include 10's which I had left out.
Are you editing the already approved translation ?!?
That will not change the Haskell version of the kata.
You either have to fork the translation, edit it, and have the fork approved ( you may be able to do this yourself, I'm not sure ), or edit the Haskell version of the kata directly in the kata editor.
I'm still not seeing any change in the published Haskell version of the kata.
You're also generating
1
s instead ofA
s, you're possibly generating duplicate cards, and you're usingfrequency
whereoneof
would be simpler ( all this in the translation, changes in which have not made it to the published version ).If and when you get the testing fixed, half of the current solutions should be invalidated. As long as you're not seeing that, the tests are not fixed.
Ok, I have fixed :
-1 to A -unique hands
However I can't edit the Kata directly, I also can't save the edited translation, and I can't save a fork because of unresolved conflicts in the description.
The relevant code :
genHand = oneof [genFlush, genCards]
genHandUnique = suchThat genHand (\h -> length h == length (nub h))
I tested this using trace as verbose doesn't work now (?) and there are no duplicates being generated.
Ok : https://www.codewars.com/kumite/5b75f90569826cc1440000da?sel=5b78806077438b40450000d1
Description merged, tests updated, but I can't approve it.
I can't approve it either; probably CodingWarrior will have to do it. Might be a good idea to put the previous comment in a new thread of its own; this is getting quite deeply buried.
Can't see why you would be unable to edit the kata directly; I have an edit link top right of this screen that works perfectly fine for me. Does this work for you?
That is odd. I can use your link (just updated the solution), but I don't get the edit link myself. Maybe it is a honor breakpoint?
That is odd.
An honour breakpoint for such a predictable link is a bit useless, no?
And many many invalid solutions! :]
I guess that worked. Let me go close an issue.
Thanks for all the commentary, I have a much better understanding of quickcheck now so I can make much more complicated mistakes obviously in the future, in the nature of Haskelling.
May I suggest that the Python version be check_if_flush
regards,
Fixed
Ruby translation kumited, with improved random tests and description. Please check and approve
I approved it, thanks!
Thanks! (resolving suggestion)
I just ammended the Python translation. Hope it is better now. Thanks for the good advice!
You could improve the random tests, to guarantee some flushes.
and note that the function name should be written in
snake_case
, notcamelCase
Fixed all the above (and more :-)
Python translation has been submitted. Please let me know if needs some adjustment. Thanks.
This comment has been hidden.
Thanks, I approved your translation, I'll try to add this to the C# and Java
Done
This comment has been hidden.
Thank you again, will fix this
Now that
10X
cards are mentioned, these is another issue:You haven't really mentioned how you define the suits or ranks.
e.g for 10 there are two common definitions, either as
10
or asT
.I added some more explanation, thanks
This comment has been hidden.
I applied these fixes, thank you for the feedback!
I have been trying to figure out how to mark the issue as resolved, it seems I need to reply again in order to do so.
I am getting this error
SolutionTest.java:15: error: class, interface, or enum expected } ^ 1 error
you forgot a
}
or have too much of them or somethign like that.Thank you.
java:
true
answer is 1/1024... => true cases have to be forced in.C#: I didn't check, but I guess the random tests will need the same update.
Yes.
This comment has been hidden.
I added the sample test and made the test method private. About the random case, I wrote the C# one, then GianfriAur translated it to Java, I assumed it was correct, thinking other's had reviewed it
they are working, but they are almost useless, for now, since this solution can pass easily.
I just looked at the c# version. At least it tests for flushes, but it has only 2 random tests. That's absolutely not enough. 100 is the normal usage.
I changed the C# code to do 100 tests, I told the other guy to check the Java one, I don't know much Java, but I'll work on it too
I re-wrote the java random test, now it's similar to the c# one
I made changes to make sure your sample solution doesn't pass :), thanks for the feedback
If you're willing to revisit random testing, I have a suggestion: ensure random outcomes, instead of focusing on random elements. You want to test flush vs non-flush, so aim to make those outcomes occur about half the time.
My idea is this: pick a random suit only for the first card. Then make the other four cards have an 85% of matching the same suit as the first card, and a 5% chance each of the other 3 suits. That results in 52% flushes, and 48% other combinations. You bias the random selection to get equally likely outcomes.