5 kyu

Water pouring problem

94 of 115sid114
Description
Loading description...
Algorithms
Performance
Puzzles
Graph Theory
View
AllIssues8Questions1Suggestions3Show Resolved
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar

    Please allow results with or without initial (0,0).

  • JohanWiltink Avatar

    ( JS )

    Function.prototype.toString should be nuked altogether in Preloaded.

    Just setting _checker.toString to something leaves the door open for Function.prototype.toString.call(_checker), which still reads the source code.

  • Nlight91 Avatar

    This comment has been hidden.

  • catslover Avatar

    Hello. I faced a problem while solving a JS task: tests [3, 5, 4, "It is possible to reach n=4 liters in one jug"] fail. The correct answer [3, 4] is specified in the task description, I even tried to substitute it manually into the return, but it didn't work. It looks like there is an issue in the _checker function in the tests. The test fails with this error: TypeError: l.at(...).includes is not a function at _checker (test.js:17:17) at act (test.js:177:19) at Context. (test.js:166:13) at process.processImmediate (node:internal/timers:471:21)

    Translated with DeepL.com (free version)

  • CaHudson94 Avatar

    So unfortunately there is an easy way to break this and succeed at all of the tests: def wpp(a, b, n): if n > b and n > a: return [] if (not a % 2 and not b % 2 and n % 2) or ((not a % b or not b % a) and not n % 2 and n < a and n < b): return [] return [(n, min(a, b))]

  • dfhwze Avatar
  • benjaminzwhite Avatar

    Approved 2022/11/28 at 5 kyu based on votes: 5 votes for 5 kyu, 1 vote for 6 kyu.

    Searched catalogue for duplicates. Author is active, all issues and suggestions resolved.

  • benjaminzwhite Avatar

    Hi @sid114 - I really liked this kata, and it seems good for approval; you've dealt with the issues and several power users have beta tested it and upvoted it.

    My only comment/suggestions are for the Description:

    • I think that the condition a <= b should be much more emphasised, it's literally the last thing in the description. Put it somewhere in the Task part that the inputs will always have a <= b.

    • In step 6 of the example (i.e. when you reach the target amount) say "We've reached a state where one of the jugs contains the desired quantity of water n=4".

    • Since you want people to return a valid path through the states rather than the number of steps, replace "how many steps" in first paragraph with something like "can you find a series of steps to reach...".

    I'm going to check through the catalogue again for any duplicates, and I'll approve once you let me know what you think about the above suggestions :+1:

  • mro Avatar

    Whats wrong with:

    >>> wpp(4, 5, 4)
    [(4, 0)]
    

    ??

    Fails the test.

  • FArekkusu Avatar

    Having multiple output types is a bad practice.

  • Glushatov Avatar

    Nice kata! However, I did not see in the description of the problem that it is not necessary to return all steps. Perhaps this is inherent in the description of the fourth possible action. In this case, it should be explained how points 3 and 4 differ.

  • dolamroth Avatar

    This comment has been hidden.

  • Voile Avatar

    There are performance requirements for this kata but is not specified. Performance tag should be added and input range should be specified.

  • Voile Avatar
    test.assert_equals(wpp(4,9,8), [20, (4, 8)])
    

    This is just wrong. The correct answer is [4, (0, 8)].

    Similar incorrect results happen in random tests.

  • Voile Avatar
    test.assert_equals(wpp(3,8,4), [10, (3, 4)])
    

    There are two ways to get the target amount of liquid in specific amount of steps, one of which results in (0, 4) and the other results in (3, 4). The test only accepts (3, 4).