5 kyu
Water pouring problem
94 of 115sid114
Loading description...
Algorithms
Performance
Puzzles
Graph Theory
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Please allow results with or without initial
(0,0)
.( JS )
Function.prototype.toString
should be nuked altogether inPreloaded
.Just setting
_checker.toString
to something leaves the door open forFunction.prototype.toString.call(_checker)
, which still reads the source code.This comment has been hidden.
That initial
[0,0]
should not be there, and that is specified ( note it says "after" every step ).Not a kata issue - but I am going to raise it as a suggestion; that initial
(0,0)
can very easily be checked for and passed.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)
We need to see your code to know why it fails.
"In one jug" does not mean "in one move". Also, the so called correct answer
[3, 4]
is only the last move of a series of moves. This is NOT an issue with the kata.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))]
this should be fixed before approving the JS translation
fixed
JS Translation
approved to avoid merge conflicts later on
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.
@sid114 FYI here are the modifications I made before approving:
moved the
checker
from the Example Tests to preloaded (it contains spoilers about the impossibility criterion fora
andb
so users can't see it anymore)added a "graceful failure" to the
checker
- checks if the passed listl
isNone
or not a list, and returnsFalse
early if so (this is so that if user tests with thepass
statement or doesn't return anything, the checker doesn't attempt to iterate through the solution)split the fixed tests into 2: cases where there IS a solution, cases where there is NOT a solution. Added a detailed error message to each fixed test (since you use
test.expect
it's clearer for users to know where they should start debugging this way).added fixed tests that check for one of the "impossibility cases" (e.g. a=3,b=6,n=2 etc.)
:)
great, anno 2023 Benjamin will translate this to JS o_O \o/
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 havea <= 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:
done, done, and done
i'll wait for you to get back on the duplication process to resolve the suggestion
cheers
Nice one - I've looked through all languages for the following topics: water/jugs/pouring/decanting/measuring/die hard and didn't find anything, so if it's a duplicate someone has come up with a realllly weird title for their version ;)
There's only 1 other kata I know of that is based around
B____t
's identity, but it's sufficiently different and besides it's not the main difficulty in this kata.Whats wrong with:
??
Fails the test.
?
there's nothing wrong with it, i've checked with the sample tests
have you mutated the input in the example tests? e.g.,
my bad. sorry.
very nice kata. learned something new.
Having multiple output types is a bad practice.
To avoid much pain later with future translations, I would return an empty list instead. None would also be a good option.
kata has been edited
an empty list needs to be returned in case the goal is unattainable
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.
it is necessary to return all steps excpet the first state with both jugs at 0 and the last step(refer the description for the same)
the fourth possible action describes a situation such as the second and sixth steps in the example provided
hopefully this cleared the doubt
thanks for the feedback!
This comment has been hidden.
So... your solution for
wpp(1, 5,4)
returns[(0, 5), (1, 4)]
. My point is that you need to write a better tester for this kata.This comment has been hidden.
This comment has been hidden.
if the goal cannot be reached, return -1
There are performance requirements for this kata but is not specified.
Performance
tag should be added and input range should be specified.done
This is just wrong. The correct answer is
[4, (0, 8)]
.Similar incorrect results happen in random tests.
format of the kata has been changed
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)
.format of the kata has been changed