7 kyu
A Letter's Best Friend
2,454 of 3,827saudiGuy
Loading description...
Fundamentals
Strings
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.
I think that it should be clearly stated that an empty string should return true. If x is not present it cannot be followed by y, there fore is cannot be true
Lua translation ! Can someone review it pls ? Thanks
Issue: The reference solution returns
false
when the text does not containa
andb
anda == b
. But it should returntrue
. An example:Yeah, you're right, I fixed this issue but when I publish the kata an orange box pop up saying "Kumite was published with failed tests". Can you help me find the issue ? I'll you tell when I find it.
Lua tests have been updated successfully. I don't know why you got that error message. But the kata editor has several known issues. Whenever you need to update a translation, make a fork of an existing translation and publish this new fork. It is easier to track changes made with forks and it is more reliable.
Okay, I'll keep that in mind. Thanks a lot for your help
Prolog translation
Approved by someone
C translation
thanks !
assertTrue(Kata.bestFriend("", 'x', 'y'), "for input: "", 'x', 'y'");
How this is returning True? in that case String txt is empty and there are no chars "x" followed by "y". Thus it should be False. Explanation: Since we are checking if "x" is followed by "y", if there is no "x", it can't return True.
Vacuous Truth. Since there is no 'x', then there is no instance of 'x' followed by anything other than 'y', therefore the condition still holds. Generally, most Katas assume a vacuous truth.
test case that checked "nodwvdwddw nmldw bdwi fobdwodw vdwfdww ldwudwjsdwm" said the program outputed False, however when checking with my own IDE it ouputs True. In additon, I found another test case which was blatanly wrong where one "e" was not followed by "y" always.
It should output
False
because "nodwvdwdddw nmldw bdwi fobdwodw vdwfdww ldwudwjsdwm" - the string contains bothdd
anddw
, which meansd
's best friend is inconsistent. I think in the later part of the comment you're referencing random tests - since these tests are generated randomly and not pre-programmed, it's important you provide as much information as you can when reporting them (what is thetxt
string? what isa
? what isb
? what leads you to believe it is blatantly wrong?). Lastly, based on your first sentence, please ensure that you're reading the error logs correctly - your_answer should equal expected_answer should be read in that order for Python. So the program is not telling you that you outputtedFalse
, but that you outputtedTrue
when it expectedFalse
.It is possible for an incorrect solution to intermittently pass the kata on the chance of a test run where no random tests are produced that have
a
==b
and neithera
norb
appear intxt
.JavaScript passes fairly often
Python rarely passes
TypeScript passes every time
(not tested for other languages)
I've noticed that the current testing approach isn't strict enough. Will rework my JS and C++ translations today to guarantee all test cases are covered.
great, thanks. I was just tetsting C++ for the same issue, but now I'll hold off
If you add tests, I can update Haskell as well. ( Please poke me under the translation suggestion, I might not get notifications for this thread. )
( In case of random tests, please write readable, maintainable code! )
I see that Java was added...
And it is rare, like Python, but the same problem remains. A coder, seeing that their code has a chance of passing, may be tempted to just opt for the brute approach of trying repeatedly until passing, even if they should know better not to.
It can be so coded that there is a guarantee that these tests will arrive during random tests.
Fix for Typescript
Fix for Java
fixed for python
same problem with CoffeeScript and Scala
(both passed immediately)
This kata has an issue. the test cases are wron so valid responses always mark wrong. it is impossible to complete in python
This issue has an issue.
Please read the Docs on troubleshooting your solution and how to raise useful issues. You are not giving sufficient information to determine any actual problems.
Most of the 2000 completions of this kata are in Python. Not impossible.
Haskell translation
this translation modifies the description
the current description has the logic backwards, and does not actually specify what is being tested. if I weren't suggesting a fixed description with this translation, I'd actually have raised this as an
Issue
.the proposed description also makes more explicit that characters are not necessarily in the string, though it still doesn't fully spell it out, and I expect people are still going to be stumped by that. they can go find "vacuous truth" in the comments ( it's in there now four times ).
Approved
C++ Translation
Approved. Please keep an eye on discourse in case of any discrepancies.
Sure, although it's a 1-1 adaptation of your random tests. Only difference, as with the JS version, is that I added some more fixed tests to test edge cases so users don't have to wait till random tests to realize faults in their implementation.
JavaScript Translation
Approved.
Why do your random test cases say that it should return True if the letter never appears in the first place? (I would have intuitively thought that in such a case, the function should return false.) The problem description doesn't explain what we should do when a letter never appears.
https://en.wikipedia.org/wiki/Vacuous_truth
Thanks! I hadn't thought of vacuous truths before. Good to know for what to do in the future.
It really is a funny problem to try to solve, but the descrition should mention the desired behaviour to the "random inputs" when it is tested against inputs that are not inside the given sentence
Description should mention what should be returned if txt doesn't contain a or either of the letters. Some solutions can pass all the basic tests but fail on radom ones when a is not present.
No, it shouldn't.
Solvers should learn about vacuous truth. This is a very fundamental logical principle, and if you get it wrong you will come to all kinds of wrong conclusions.
Closing.
Definetly not an 8kyu, but funny to solve :)
It is no longer 8kyu.
This comment has been hidden.
You're wrong. You are not implementing the specs. Closing.
TypeScript translation based on existing CoffeeScript translation
Approved
Scala translation
approved.
CoffeeScript translation
approved.
java translation
This comment has been hidden.
lol i have the same problem like u bro like i don't even know why best_friend("jtekeh dek wbwclw gykc", "i", "h") should return True, even the string have no "i"
the concept is called a vacuous truth. the tests are correct
This comment has been hidden.
This comment has been hidden.
Closing.
this is very educative kata i think but it would be nice if i could solve it
I personally would rewrite it to something down the lines of: "Everytime the first letter appears in the string, the second letter has to come alongside it. If not, then return 'False'."
The worst piece of trash I ever solved on Kata. It's a shame CodeWars that you allow garbage like this to be published! Delete it!
You can skip the Kata if you don't like it.
Hi armM00, I'm sorry to hear that you weren't happy with this kata. I future you can downvote katas or skip them instead of taking to the comments. I would also suggest trying some more katas and finding ones that you enjoy :)
absolutly right it gives false for random tests that has two same letters which are not even in the string! such a waste of time
@armM00
@AssafBenIshay
If you find a problem with any kata, you can always post an
issue
.Be sure to include a clear description of the problem, and provide examples of where it breaks, such as input, expected output, and a proof of how the expected output is incorrect by the lines of the description. This way, you can contribute to the quality of this site if you are willing to do so.
There should be tests where the first letter appears at the end of a string. For example:
Some solutions return
True
for this test case. But the expected result isFalse
.Added.
i used 11 strings to solve it, and the random guy it in 1, uhhh
For the record, this is not 8kyu and should be sent back to beta if possible...
Hi,
I was in the middle of editing this kata, but someone approved it. I don't have the authority to send a kata back to the beta process.
Sent to beta, going to re-approve...
Re-approved as 7 kyu
Add a condition where
a
andb
is the same letter and put on the end of string.Example:
txt = "abcdee", a = "e", b = "e" -> False
txt = "abcde", a = "e", b = "e" -> False
@Mednoob, good point.
txt = "abcdee", a = "e", b = "e" expected to be False but it should be True as per description. But then, what about 'abcdeee'?
Let's clarify that a and b are not equal in any of the test cases. What do you think?
No, sorry that's not what I meant. I didn't thought of this, but the main problem here is not same letter put at the end of the string. Main problem here is there's no explanation for the behavior of the function when handling the letter at the end of the string.
According to the explanation, I think the example given by me should be
False
. Because, from the description:If the first given letter be put on the end of the string, then it means that the given letter doesn't appear immediately before the other given letter and therefore should return
False
.Added test cases.
The description is unneccessarily convoluted. It really just means "if a given letter always appears immediately before another given letter in a word" (therefore whitespace is a boundary).
Removed from description.