Ad
  • Custom User Avatar

    it is very likely that one hand get used multiple times

    So, that's it! Thanks, now totally explained.

    In all of the initial tests Hands are created, tested once and then freed. That let me to the assumption that it would always be that way. My mistake. Thanks again.

  • Custom User Avatar

    Thanks, but that result would be expected - buildTracker() should indeed set values into the tracker field.

    Let's use your test approach, but before any calls to buildTracker:

    Result compare(Hand *pl, Hand *op) {
      int checksum = (pl->tracker == 0) + (op->tracker == 0);
      // Both tracker values were set to 0 by PokerHand, so they should still be 0 now.
      assert(checksum == 0);
    
      // tracker fields will be updated by buildTracker().
      pl->type = buildTracker(pl, pl->cards);
      op->type = buildTracker(op, op->cards);
      Result retval = _compare(pl, op);
      return retval;
    }
    

    Output includes:

    boxfort-worker: solution.c:199: Result compare(Hand *, Hand *): Assertion `checksum == 0' failed.
    
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Seems not fixed to me. I was given the test:
    "JC 6H JS JD JH", "JC 7H JS JD JH"

    Both hands contain 4 Jacks. For this to be possible, there would have to be at least two decks of cards in use. To be fair, the description does not specify whether a single deck of cards is used, but I think most people would assume that's the case.

  • Custom User Avatar

    I agree, the correct solution for 96682790625023136 is { 9668279062523136, 11, 0 }

  • Custom User Avatar

    Tested with large random integers, this seems to be about 100 times the speed of some solutions here - those using strings and brute force.

  • Custom User Avatar

    Thanks for the feedback. I was running your code to test it... maybe I made a mistake and forgot to compile and it was somebody else's code :) I'll check again when I've got a moment.

  • Custom User Avatar

    Despite passing tests here, this solution is flawed. I'll fix it when I get a moment.

  • Custom User Avatar

    Try testing all possible moves - you will find it fails on 8 of them.

  • Custom User Avatar

    If you test it with all possible moves, you will find it fails 8 of them, returning 2 when it should be 4.

  • Custom User Avatar

    Sorry to say, it fails on 4 tests:
    Fail: b7 to a8 - returned 2 should be 4
    Fail: b8 to a7 - returned 4 should be 2
    Fail: g7 to h8 - returned 2 should be 4
    Fail: g8 to h7 - returned 4 should be 2