Ad
  • Custom User Avatar

    In random tests, if theHand is mutated the hand annotation that is displayed for the respective test becomes completely wrong.

    It doesn't break the tests, but it makes the displayed result very misleading.

  • Custom User Avatar

    the direction was to write the factorial function not to import the existing one

  • Custom User Avatar

    bruh.. import factorial, genius! lol

  • Custom User Avatar

    That's great. I thought in this direction, but I failed in the end and changed my way

  • Custom User Avatar

    Them's just the rules. Specifically, a 4-card flush is scored only when the four cards in the hand are of one suit. If the start card happens also to be of the same suit as the four cards in the hand, one would score a 5-card flush instead. Even better, when scoring the actual crib hand, only a 5-card flush is counted (that's not a factor in this kata, btw).
    I'm sure these rules exist for reasons other than to confound newcomers to the game but that said it's an odd little game with a fair complement of odd little rules.
    I can see that the language in the kata description could be improved to better emphasize the restrictions pertaining to the scoring of flushes. I'll edit and re-publish it shortly.

  • Custom User Avatar

    Btw, how is it that the flush rule forbid this to be considered a flush? ['.S','.S','.S','.H'], '.S'

    Or maybe there is an error in your code? Because that's one of the things that is weird in the description: one never knows if you're talking about "hand+start" or just "hand", when you say "hand". And all other rules are using "hand+start", iirc.

    => ??

  • Custom User Avatar

    Hi,

    Yes, python is my "go to" language. Don't hesitate if you have questions.

    cheers

  • Custom User Avatar

    I'm actually comfortable now with 4,000 randos. I might add a set of edge/corner cases that the testing code draws from (using random.sample) periodically as it dispenses its 4,000-strong maelstrom of test cases.

    I'm humbled by your solution, btw. I have been an assembler and C (IBM mainframe, so yes COBOL too) programmer for, let me see...
    ...let's just say a while and leave it at that. Anyway I dived into Python last year and I know that your solution would have have been impenetrable to me earlier this year and now it intriges the heck out of me so that's progress. Is Python your go to language? There's a savant quality about it (which I say as a compliment) that alludes to a comfortable familiarity with the language and its armada of libraries, and/or an inate savant ability.
    Okay I'm being facetious but seriosly, nice work. I may have questions yet...

    Cheers

    Kevev (K3nH2l) Hall

  • Custom User Avatar

    note: you actually can keep the 20000 tests if you modify your code this way:

        @test.describe('Random tests')
        def random_tests():
            nonlocal errors
            for testn in range(20000):
                ...
                if scr == ans: continue
                ...
            
            if not errors: test.pass_()
    
  • Custom User Avatar

    I cut the number of tests as suggested. I was really more concerned with coverage than performance tho. Stll, Im keen to scope out your solution later today. I only started playing with Phython at the end of last summer and I'm quite impressed if not totally comfortable with its eschewance of static type-checking and its insistance that indentation is a programmatic determinant of logic flow.

    Anyway, this was challenging but it had me scrambling at an enjoyable level of intensity.

  • Custom User Avatar

    :)

    Was a pretty nice one. Trickier than it looks at first seight.
    Your logs, for debugging, are really good and helpful. Nice work. Surely I wouldn't have spotted the problems without them.

    I'm "worried" about the number of tests, tho. With that much tests, you're killing my browser, actually x)
    It could be good to silence the assertions when the answers are correct. Maybe adding at the end a log telling how much tests were passed or executed when you interrupt them (when more than 100 fails)

    Btw, why so many tests? I thought for some time that it was about performances requirements, but the execution time drops from 8s to 3.5s when I test your function (as ref and user) vs mine (as ref and user too). And I bet that a good part of those 3s are used for test generation, meaning your solution is "awfully" slow... (tho, my solution could be optimized further, when it comes to combos15)
    Here I'd say there are two options: either improve your code and add time constraints (not relying on the time out, tho. I can help if you wanna go that way), or reduce the number of tests to something like 4000. That's way more than enough, I guess? (but maybe there is a reason for the choice of 20000?)

    EDIT: I checked the perfs more precisely for the random tests: mine: 2,2s / yours: 6,3s. I'll try to see if I can go further with mine... (edit²: well, I could gain somewhere around 15%, maybe... Doesn't worth the effort, I guess)

  • Custom User Avatar

    Okay, typos have been fixed (note that "players' scores" is is correct because plural nouns ending with "s" become posessive by the addition of an apostrophe alone).

    I agree about the pre-loaded code. It prods potential solvers unnecessarily. The less I give them, the more likely it is that they'll find a solution more elegant than mine. I moved the pre-loaded code to my complete solution (since it uses it). I'm new to Python and I was probably overly enamoured of my one-liner dictionary comprehension.

    I also changed the representation of 10-cards from "X" to "T" and reflected this in the doc, testing code etc.

    Primped, polished and republished.

  • Custom User Avatar

    Hi,

    Typo in the description:

    • "Cribbage is a card __g__ame for two persons"
    • "until one of the players' scores reaches"
    • "The characters used to represent card suits are:"
    • "'XD' is Ten of Diamonds" -> no, it's a smiley... (sorry, couldn't resist x) ). Note tho that 10 are usually represented by 'T'. Not a problem, tho.
    • "Aside from the royal cards" -> "figures" indtead? (dunno)

    Other than that:

    • I'm not sure that the DECK_DICT is really useful. Coding the rank of the vards isn't difficult at all. Not a problem, ofc.
    • Mmmmh... I'd even say that all that is in the preloaded section should be removed. Or at lest, don't provide the suitVal field: with this, you're orienting the implementation. Let the user build his own set of data.
  • Custom User Avatar

    Thanks for the quick feedback. I've addressed all the issues you raised and re-published

  • Custom User Avatar

    Hi,

    • running the initial solution:

      Traceback (most recent call last):
        File "main.py", line 1, in <module>
          from solution import *
        File "/home/codewarrior/solution.py", line 4
          return score
                     ^
      IndentationError: unindent does not match any outer indentation level
      

      => you have a tab char at the first line inside the function. Replace it with whitespaces

    • typo in the first sentence (at least, didn't read the full thing yet): crad

    • 20000 tests: I hope you silence the assertions...? Otherwise you'll kill most browsers with that much tests. Seems you didn't silence them => need to be changed.

    • why so much tests, btw?

    • instead of dots, to separate the sections in the description, use <br> with emtpy lines above and under it

  • Loading more items...