Ad
  • Custom User Avatar

    With input "abc(" it loops forever.

  • Default User Avatar

    It is a good example of how lambda expressions can be used though. This solution enlarged my perspective.

  • Default User Avatar

    Thanks for making my day man xD

  • Default User Avatar

    Thanks for this great explanation

  • Default User Avatar

    Random test cases are susceptible to cheating.

  • Default User Avatar

    I have just taken off my hat...

  • Default User Avatar

    How can the result be 9 for n=12 - the last sample test for java:

    assertEquals(9, Solution.cardGame(12));

    I find the result 8 on paper. Am I wrong??

  • Default User Avatar

    I considered this, but note that the description says Suppose a variable x can have only three possible **different** values (emphasis mine). Even if it was possible that the author intended that the "different" values could in fact be the same value, (or, maybe meant possibly rather than possible), when in doubt, I consider the test cases to be a solid indicator of the author's intent unless they themselves later say otherwise.

    Looking at the test code itself, each translation seems to have code that specifically prevents duplicates, by choosing again, by choosing from distinct ranges, using a built-in API for distinct random choices, or even simply skipping that test, so I'm leaning towards it being intentional.

  • Default User Avatar

    This solution is not quite correct. I assume this passed the tests due to non-comprehensive test conditions. For instance consider the following case:

    f(x=3, a=3, b=5, c=3) # This is the calling function

    In the above case x must take the value "5" since its current value is "3" (Problem says: "You wish to assign to x the value other than its current one."), but the result of this solution is "3".

    The reason is that dictionaries do not allow duplicate key words. When you do {a:b, b:c, c:a} for the above test values, the value of a (3 as keyword) will be 5, and when program see that c is the same with a (in terms of keyword), instead of creating a new key-value item, it will assign a again but this time with the value of 3.
    So, the last dictionary will be {3:3, 5:3}, in which case the value "5" is unreachable which is the accual correct answer.

    I hope it helps...
    Stay safe :)