6 kyu
Zero-plentiful Array
1,379 of 2,472aweleshetu
Loading description...
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.
Why, for this example, equal 0? [3,0,0,0,0,6,9]
That test expects 1 as result.
Yes. But when I clicked "Attempt", I've got this result -
for array : [3,0,0,0,0,6,9] : expected +0 to equal 1
Then your code returned 0 instead of 1, the format is:
Thanks!
I had to figure out the task by reading the comments, "...every sequence of zeros is at least 4 items long" is a bit misleading, I don't think the description is very clarifying, however nice kata, it is a little bit more complex than expected.
Why is that misleading? How would you write it better?
The array is defined zero plentiful if and only if all sequences of consecutive zeros are at least 4 items long otherwise return 0. I don't know, does that sound more clarifying?
I really don't see the difference between "every sequence" and "all sequences", but I'm not an english native speaker.
Me neither, understanding the description is a challenge in itself often times.
Typo: oherwise should be otherwise.
fixed
The description is nothing explain.
But it explains everything :/ How many times do you see 4 (or more) consecutive zeros?
I can't understand that part. If number of zeros less than 4 What am I do?
Return 0.
I got him. This kata did sweat to me. But I got him finally. Thank B1ts and Krono79 for help me. Especially If number of zeros less than 4 parts to very hard for write the code.
Stupid task: a vague theory that is misleading
Thanks aweleshetu!!
Nice kata! Took me more time energy than i thought it would take!
I didn't read the instructions carefully and that threw me for a loop.
The case where there were enough zeros right before the array ended kept messing me up. This was a bit challenging for 6kyu.
Some tests are broken, example: (2, [0, 2, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0]) should equal 0 It says there is no sequenses of zeros.
Hi @Billy696 and welcome to Codewars;
I think you have not read the description correctly - you need to consider that:
"... every sequence of zeros is at least 4 items long."
In this example, there is a sequence of zeroes that is not 4 items long (it is the first sequence, consisting of one 0). So the expected answer is indeed 0 for this input.
If the input had been
[2, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0]
where I have removed the first0
then the answer would have been 2, because here every sequence of zeros is indeed at least 4 items long.Thank you for your explanation. I read description again and understanded my falt
The test cases for the Javascript seems to be broken...
for array : [0,2,0,0,0,0,3,4,5,0,0,0,0,0] : expected 2 to equal +0
for array : [0,0,0,0,1,0] : expected 1 to equal +0
for array : [0,0,0,0,55,0,0,57,62,-45,0,0,0] : expected 1 to equal +0
The tests are fine.
python fork with new test framework
Approved
This comment has been hidden.
i substantially improved the RNG in Python
Help! i'm fail in Basic tests 7* (7 of 8 Assertions), a don't know where am i going wrong or what kind of input comes in test 7 that is breaking me.
Hi - please don't use issue tag, that is reserved for problems with the kata itself, not problems with your code/debugging.
I just solved in Python and it works fine. If you are sure you are failing on basic test #7, then that means you are failing on this input:
[0,2,0,0,0,0,3,4,5,0,0,0,0,0]
It's up to you to debug, but looking at your code: I recommend you re-read the first line of the description again to see if you are missing another condition for this kata.
More generally, here's a very useful troubleshooting tip: you can always print the test input by adding the following line in your code:
now you can see the test cases you fail in the console. Hope that helps.
You can read more about this here:
https://docs.codewars.com/training/troubleshooting/#error-messages-and-printing-your-inputoutput
pls fix tests for Python
What exactly should be fixed? The tests are fine.
Your code is wrong. It returns 2 for this input:
[0, 2, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0]
The first 0 there is a sequence with only 1 element.I know, but we have 2 sequences where zero appears 4 times in a row or more
I've just understood, thank
but i could not '__'
Why are some of the test answers supposed to be 1 for Python? Surely any of the cases where there is only 1 string of 4 zeros should return 0?
Read the description again.
Not a kata issue.
Thanks for that explanation, silly me.
Factor translation
Approved
Can't see test cases on half the ones not working, why is this
JavaScript test cases do not provide arrays like
[1000, 0, 1, 0, 0, 0, 0]
or[10, 0, 0, 0]
. Many existing solutions will break on such tests.As I can see, the same issue was already closed for Python 4 years ago. But for JS, the problem is still relevant.
turns out even the reference solution was wrong, and there were no random tests
added as fixed tests + added random tests + upgraded to Node 14
Hi everybody. Please, can somebody clarify, why sometimes the same code passes a different number of random tests?
The tests are random, this means that every time you run the tests, the inputs (and expected outputs) are different to the previous time you ran them.
If your solution isn't quite right, and fails for some input (but not all), then this is why you will see the same code passing a different number of tests each time you run it.
The key is to look at a failing test and understand why your solution doesn't pass that particular case, and fix it. Then rerun, and repeat.
Does that help?
Yeah, it definitely helps. Thank you!
A very nice Kata to (re)learn a very useful build-in package. With that my first idea shrunk to basically 2 lines.
Replies to previous questions indicate that, for example, the answer for {0,0,0,0,1,0,0,0} should be 0 because "every group of zeros has to be at least 4 items long" Could you please explain why the first four zeros are not considered to be a group of 4?
but the second group is not. if there is ANY group of less than 4 zeroes, then the array is NOT 0-plentiful, and you should return 0.
If EVERY group of zeros is of length >= 4, then you return the number of such groups.
Why is the answer 0 for {0, 0, 0, 0, 1, 0, 0, 0}? 1 should be
Error in tests for C
Please provide a clear example of failed test.
https://prnt.sc/1wu4pxk https://prnt.sc/1wu4tkh
because every group of zeros has to be at least 4 items long; although the description is not really clear about this
Python test framework should be updated (read more here if needed)
fixed by fork
Too lazy random tests in python: expected result = 0 in 99.9999% of the cases
fixed
Ruby translation kumited, including updated description and proper random tests. Please check and approve!
Approved by someone
C translation
Thanks :)
There's a problem with basic test cases I had not seen. The line
int foo(int,int);
produces an error. Attempt tests are ok. Can you review it?its weird, i had forgotten to fill the sample tests panel ^^ republished, you may need to reset the editor to see the changes
How do I reset the editor?
at the bottom of the trainer page there is a "Reset" button between the "Discuss" and "Test" buttons
I tried that, but seems it doesn't work... I'll try from another computer in some minutes.
Sorry, it's ok, I thought you meant I had to approve a new fork.
ah sorry if i wasnt clear i only modified the sample tests and since they are cached by the browser sometimes they dont update when a new version has been published
When I run the test for arr = [0, 2, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0] my solution returns 2 where the result says "ERROR: 2 should equal 0" I'm confued. Wouldn't the array have 2 sequences of plentiful zeros?
This comment has been hidden.
This comment has been hidden.
Both conditions should be met to consider the array zero-plentiful, and your code would fail in this case too:
[1,0,0,0,0,0,0,0,0,1]
there is only one sequence there.Oh ok. I think I get it now.
'every sequence'
This comment has been hidden.
Working on my soluiton after the issue raised by lechevalier, I realized the tests are missing cases with only 2 or 3 consecutive zeroes too! (this solution shouldn't have pass with the limit check at 7 instad of 11)
flaw fixed and invalidated the mentioned solution, thanks for reporting :)
This comment has been hidden.
i will fix that, just give me couple of days :)
Only a test to add, I can fix it if you want ;)
thanks for suggestion, flaw fixed :)
It should be a mandatory test :-O
it is :)
Thank you, it was interested to solve
log:
[0, 2, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, 0, 0] ['0000', '00000'] 2
This array has 2 patterns matching and so the length of my array is 2. But I get an output of: 2 should equal 0. Why is this?
There are 3 sequences of zeroes there and not all are of length at least 4.
ah so ALL of them must be at least 4. Thank you for helping me clarify that!
I've realized that some people would pass this without having this array give 0 as a result: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0] It might be a good idea to include it in the test part. Sorry I'm still very new to coding and this site, I'm pretty aware that there might be a lot of methods for which this doesn't make any problem ;)
Python translation Kumited.
Please review adn approve.
Not sure you saw this. Please review.
approved by someone
See issues above
cheers
This comment has been hidden.
why was it incorrect ?
This comment has been hidden.
Sorry guys, I don't get all requirements.
Approved
FYI - the initial solution now does not match the description because it still says return null
Fixed
Why return
null
if not zero-plentiful? Why not just return0
if there are no sequences?That way function has the same meaning, but avoids the muddle of different return types.
Maybe return
-1
instead ofnull
.0
is a valid return value.Even then you're doing two different things in one kata, but that's not really a problem here.
The problem with returning
null
is that it has a lack of concern of types, and hence is not portable to other languages (e.g C# and Java).weird, DM had a suggestion one day ago and i just get notified. But i will change it.
@JohanWiltink
Yes. That is precisely my point.
The description says "return the number of zero sequences if the array is zero-plentiful", but due to definition of zero-plentiful it might as well just say "return the number of zero sequences".
Trying to bend 2 meanings from 1 result will just end in tears when some unsuspecting caller forgets to check for the special case...
I think we should leave it this way than invalidating some awesome solutions. what do you guys think ?
Please decide quickly, we need your decision before we can approve the kata ;-)
@አወል እሸቱ You already know the right thing to do, but seem to be lacking the courage to do it! But this is what "Beta" is for.
yes, its corrected now :)