7 kyu
Return substring instance count
2,005 of 8,204jhoffner
Loading description...
Strings
Fundamentals
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.
Haskell translation
This comment has been hidden.
This comment has been hidden.
you did not use markdown formatting, so your code is hard to read. from what i see, you seem to be only considering the case
len(search_text) == 2
, but your solution has to work for any length.You should ask a
question
to ask for help;issues
are provable bugs within the kata. this guide can help you troubleshooting your solutionThis comment has been hidden.
matchAll()
does not return an array, it returns an iterator. An iterator has nolength
property, and JavaScript defaults toundefined
when you access a non-existent property on an object.This comment has been hidden.
This comment has been hidden.
Python update (new testing framework)
Approved
This comment has been hidden.
Falsifiable (after 14 tests): "zzaaaza" "aaaz" 2 expected 2 but got 1
I don't get this kata. How can you find "aaaz" from "zzaaaza" twice?
C translation (without overlap or empty substrings)
Approved
this should be level 8 , no need to be 7
Not all languages are so trivial, so, 7 kyu is ok. Note kata ranking can't be changed either.
I see.
The description doesn't say if we should count overlapping substrings. This should be stated and all versions should be coherent with it; currently there are no overlaps or they should not be counted in Python, but it's the contrary in Haskell and JS.
I don't see any overlapping test in JS, are you sure about that?
My bad, not in JS (but in Haskell).
Haskell fixed ( ~60 solutions invalidated :] ); description already mentioned overlap not allowed ( probably did not always do so ).
Closing.
In Haskell the substring may be empty, and we are supposed to return the full string length in that case. It doesn't make sense.
perhaps
full string length + 1
would make more sense :pafter all
O_o
Well, in Python too there may be empty strings... To me the logical answer to this would be infinity...
Substring is now never empty. Closing.
(
length + 1
would make sense to me, but try explaining that to the target audience of the kata .. )This comment has been hidden.
This comment has been hidden.
BROKEN KATA
Broken how?
Why does an empty string substring match length of the string times? Should this behavior be explicitly called out in the instructions?
The tests need a complete rewrite to include random tests.
Issue not useful without mention of affected languages. Closing.
When reopening, please specify language(s).
Issue on C# Can't submit my solution : fixture.cs(23,71): error CS0120: An object reference is required to access non-static member `Kata.SubstringCount(string, string)'
Fixed sample code.
Kata.SubstringCount
needs to bestatic
Thank you for helping, it works !
In the testcases the function is called
solution
but in the function declaration it'ssolve
.Fixed (it's Haskell version btw).
Ah yes, sorry -- I should have realised that the issue wouldn't automatically be tagged with the language.
Haskell translation
Please review and approve.
Old and too simple... Nothing to gain for new Python players... Nothing to gain to translate it in Python except points on the leaderboard...
This comment has been hidden.
While I appreciate reading new katas, even simple ones, this kata brings nothing to a beginner more than reading documentation: literally nothing more than a built-in function. From more advanced player's view, it is extremely boring to see nothing new but such tremendously simple katas. Boringness won't help CW keeping both new and old players entertained.
Moreover you translated a three year old inactive kata that even a profilic kata creator stated as unqualified. I simply didn't grasp the point of your decision at the moment and I still don't grasp it now. You explained that you translated this kata to see when people start complaining: I don't usually have much to complain about your katas, but if that is your only purpose, I find it quite mischievous - I think CW is a place for sharing and entertainment, so please refrain yourself from bringing such madness here and keep the good work!
This comment has been hidden.
Then just two questions:
Ad 1st question: As I know, it's possible. But after I'd seen kazk's struggles with adding new stuff (see here) I decided rather step back as I have other things to do :) In my understading, the 500-solvers rule isn't solely a technical issue. jhoffner could tell more about the motivation behind this rule.
Ad 2nd question: Maybe, I've never tried to check what 3rd party libraries are available. However, use vanilla JS without third party stuff (immutable.js, JQuery etc.) to feel the "authentic pain"* :D I remember my feelings (or frustration :)) when I first tried js.checkio.org and I had to write 10 lines using
for
s andif
s instead of a cute, little Python one-liner :)Regards,
suic
* To be honest: I don't like JavaScript. On the other hand, I don't think that JS is an a priori bad language :)
This comment has been hidden.
This should be a very old Kata, with the CW standard to measure it now, it is not qualified.
It does not have example testcases,and random testcases, and the difficulty is not suitable as a 6kyu.
It's 7 Kyu
Shouldn't there be a test case where some strings are uppercase? The more popular solutions would fail that case, wouldn't they?
I think this is a bit easy for a 6 Kyu.
It's 7 Kyu
This comment has been hidden.
Imagine having an input string like "ababa" - you want to count the b's.
Split on b will chop up the string into three parts - similar to what you naturally do ig the b's were replaced with a comma. In this case it will count one item too much as you are really just interrested in counting the commas.
Scan on the other hand will pick out only the b's ignoring the rest giving you a count of two b's.
thank you very much for your reply. like 'abab',i want to count the b's. when the last letter is b after I use the 'split' method,the result will be two. 'abab'.split('b') = ["a","a"] that's where i am wrong .
Wow. The kata is that popular and old, but have some problems.
#First Tests check too few cases. My solution had serious bug, but have passed the tests, because it's not too unlikely to pass only 4 tests when a solution does almost what it must.
#Second The description doesn't state, what kind of text a solution must accept as input. Is it alpha-numeric only? Or is it a regular text - "Yo, man", "whatcha gonna do", etc.?
It looks like most of people who solved the kata have considered code examples in the description as a hint like "no special characters here!". So the best solution is to state "Input string consists of a-z, A-Z, _ and space", for example.
This comment has been hidden.
Read carefully about return values of String.match. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
Thanks Firnis. In most of the kata I've done thus far, the Attempt method returns some type of error message when it does not work, so I was looking for that. Didn't think about returning null vs. 0.
How about adding empty string to possible searchText values? Test.expect(solution('aaaa','') == 0);
Also Test.expect(solution('aaabb', '.') == 0, "solution should not assume search text is safe to use as a regular expression")
Excellent suggestion. Adding that will break probably every single solution given. I think I might create a new, harder version of this kata that takes the following signature:
Unless of course someone else is up for creating the new kata and earning the honor for doing it :)
First post? http://www.codewars.com/dojo/katas/52190daefe9c702a460003dd
You rock!
Test.expect(solution('aaabb', 'aa') == 2, "solution should return correctly count overlapping search results ")
I agree with this. I built my solution with this in mind.