Ad
  • Custom User Avatar

    What B1ts says doesn't imply changing the order of the list.

    There are two ways to give change for a $100 and one is more efficient than the other.

    Vasya can successfully give change to everyone in this case without changing the order:

                          Queue | Till           | Transaction
    25, 25, 25, 25, 50, 100, 50 |                | - 
        25, 25, 25, 50, 100, 50 | 25             | Take one 25
            25, 25, 50, 100, 50 | 25, 25         | Take one 25
                25, 50, 100, 50 | 25, 25, 25     | Take one 25
                    50, 100, 50 | 25, 25, 25, 25 | Take one 25
                        100, 50 | 25, 25, 25, 50 | Exchange 25 for 50
                             50 | 25, 25, 100    | Exchange 25, 50 for 100
                                | 25, 50, 100    | Exchange 25 for 50
    
  • Custom User Avatar

    Then the Kata is not clear on that. It mentions nothing about being able to shuffle people around. When most people think a line, they think first to last, one after the other.

  • Custom User Avatar

    how do i answer [25, 25, 50, 100] = true ?

    The clerk collects 25 (no change), then another 25, then he receives 50 and gives back 25 change. He now has 1 x 25 and 1 x 50 (exactly 75), which he gives to the next customer and keeps the 100.

    Out of the two options you provided, #1 is correct.

    Does that make sense now?

  • Custom User Avatar

    Okay.. so if I used that logic: how do i answer [25, 25, 50, 100] = true ?

    To explain in detail, these were the two encounters I tried to go with:

    1. The change that the clerk can provide INCLUDES the ticket that is sold to the person
      e.g. Clerk has 50, customer gives 100: Clerk has enough change because (remainder of 50 + ticket of 25) = 75
    2. The change that the clerk can provide DOES NOT INCLUDE the ticket to be sold to the person
      e.g. Clerk has 50, customer gives 100: Clerk does not have enough of change because customer needs 75 and clerk CURRENTLY only has 50
  • Custom User Avatar

    If the clerk sold a ticket to that person, the clerk would've had enough of change

    No, he wouldn't have enough. The clerk would receive 1 x 100 bill, and he has only 2 x 25 bills to give for change (not enough for 75 needed)

  • Custom User Avatar

    "Should return false for {25, 25, 100}"

    I don't quite get this, because the clerk would've had 50 by the time it reached the 3rd person in line. If the clerk sold a ticket to that person, the clerk would've had enough of change at 75 which is needed by the customer.

    I used this logic because it applied to other test cases, or the other cases would've failed.

  • Custom User Avatar

    Not a kata issue.

    for the next customer who pays 50

    Don't you think you could use that 50 to give change for 100? The test case is correct.

  • Custom User Avatar

    Test given: [25, 25, 25, 25, 50, 100, 50], to return True; However this is not the case because after accumulating the first four customer's money, the toal adds up to 100, leaving a 25 change for the next customer who pays 50, the total becomes 75; leaving a 75 change for the next customer who pays 100, the total becomes 0; the clerk does not have enough change for the next customer who pays 50.