6 kyu
Loneliest character
577 of 1,381aplefull
Loading description...
Strings
Algorithms
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.
Nice kata. Had fun solving it
Haskell translation self-approved.
Nice kata. Enjoyed it.
python new test framework is required. updated in this fork
Approved
this test is worng Assert.AreEqual(new char[]{'g'}, Kata.Loneliest("abc d ef g h i j ")); the answer most be 'j'
The test is fine, read this:
And next time use markdown formatting when you don't want spaces collapsing: https://docs.codewars.com/training/troubleshooting#post-discourse
It was also discussed two posts below yours: https://www.codewars.com/kata/5f885fa9f130ea00207c7dc8/discuss#6500501b3ee338585bc42721
'refb l miq hj ko n g p a c d ' This test and some other tests fail because of the ORDER of the elements in the resulting array. But according to the description of the kata the order should not be taken into account! The fail message is that the test expects the first element to be 'g', but my code makes it a 'c', which is correct too and it's just the second element in the tests, not the first like I have it.
PS: To make the tests order-insensitive you could use this code instead: assertThat(LoneChar.loneliest("refb l miq hj ko n g p a c d ")).containsExactlyInAnyOrder('g', 'c');
Confirming this is an issue in the Java version; will fork and rectify.
Fork addressing this issue here: https://www.codewars.com/kumite/6503a985c1845360d6bff45b
Would appreciate review; the new order-agnostic equality check isn't efficient but it's more than fast enough for this kata.
Fixed in latest fork
how the output will be "g" assert.deepEqual(loneliest('abcXdXXXefXXgXXXhXiXjXXXXXX'), ['g'], "result"); g = XXgXXX = 5 j = XjXXXXXX=7 Answer should be J instead of g
And it has been already asked and answered here
Java translation
Approved by someone
Really funny and challenging kata, compliments.
Ruby 3.0 should be enabled, see this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Not a native in ruby but made an attempt to update test fixture. It works with MRI 3.0 now, let me know if there are any more changes that need to be done
The test seems to be wrong here. There are many test where I tried to count and the result was different from my brain o.o
The test seems to be wrong in my case. I even went and count each spaces and the test always give a wrong result
Presumably, you do not count the right way.
This comment has been hidden.
ok, It was my mistake. I did not understand the kata properly. I solved the issue. Nice kata
Not an issue. A misreading from you.
Amazing kata!
In the C# translation, main class is static, so it's impossible to create local variables. (Make function static instead of class)
Thank you, fixed!
excuse me I am beginer, how could I see what is Randomtest input?
Depends on the language you are working with. Just print the argument of the loneliest function.
In case of js it's
Printing them ?
Really nice problem. But a bit too difficult for a 6.
A bit too easy for a 6.
Why do i have this error for a test: "result: expected [ 'd', 'z' ] to deeply equal [ 'z' ]". other tests seem okay
test.assert_equals(sorted(loneliest('abcXdXXXefXXgXXXhXiXjXXXXXX')), ['g']). Isn't it supposed to be ['e', 'f', 'g']? 3 + 2 = 2 + 3
No, 'e' only has 3 spaces and 'f' only has 2.
Ohh, got it. Thank you for reply <3
but what about 'e' and 'g'? They have same number of spaces
You count spaces from both sides.
Ruby translation kumited with slightly cleaner description -- please check and approve!
Approved, thank you! And that's a really nice description :^)
Great little kata, thank you, aplefull. Could be just me but I'd rate it slightly higher.
Objective: character(s) that have the most spaces to their right and left. Test #2: array-->"abcXdXXXefXXgXXXhXiXjXXXXXX" (X corresponds to space) Spaces for 'g':2+3=5 Spaces for 'j':1+6=7 Solution would be ['j'] and not ['g']...isn't it?
String can have leading/trailing spaces, you should not count them;
This comment has been hidden.
This comment has been hidden.
Oh, translation problems, sorry for that. Should be fixed now :^)
marking as resolved
In the python tests, there are cases where there are more than one of the same character, going against your rule of there only being unique characters.
Should be fixed now.
python translation (solution section): "def loneliest():" # <- the input parameter is not present D:
Oops! Fixed now.
:p
Here is a python translation.
Approved! Thanks for the translation.
This comment has been hidden.
This solution is actually supposed to pass. Strings in tests contain only unique characters from a to z, and many of people's solutions actually rely on this. They won't pass anymore if I change the tests.
Ah. Well, might want to add something in the description about all characters will be unique just so you don't get more comments like this. Great kata, btw.
Yup, i added a note now. Thank you!
Hi,
=> use this:
Fixed. Completely forgot about that, thank you.
:+1:
Returning inconsistent datatypes is not a best practice.
Changed. The function should always return an array now.
This note should be removed.
Done. Left note about the order of characters (just in case).