7 kyu
Broken sequence
1,527 of 4,401suuuzi
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.
JS should be updated to Node 18
This comment has been hidden.
The returning values are a bit confusing (1 when it's invalid and 0 when it's valid is the opposite of True and False in Python for instance) but I get it.
What I don't get, is how a valid input with NO missing number should return 0 but an empty input should... also return 0?
Especially since it is written in the description that we are looking for a sequence of integers starting with 1.
According to the description, it should be either:
In both cases, the return value should be 1, not 0.
If the sequence is valid, the return value should be 0, not some missing value:
Returning
0
, as per stated in the description, involves 2 conditions:As I said before, an empty sequence is either considered:
OR
1
An empty sequence doesn't satisfy both conditions for returning
0
.And
1
is the missing number because as stated in the descritpion:"Check if the elements are part of an ascending sequence of integers starting with 1".
I'm begginer my test pass all except :
test3Digitnumbers It must return 90 expected:<90> but was:<1>
Tricky, but nice Thanks suuuzi
This comment has been hidden.
like and share your views
fvck
Haskell : https://www.codewars.com/kumite/5b9c4f9683c250ce66000122?sel=5b9c4f9683c250ce66000122
(note the description needs to be fixed in the translation, I need to know how to do a default language).
Description is now fixed to reflect haskell and not-haskell.
Ref : https://medium.com/@Codewars/latest-updates-new-languages-version-updates-smarter-markdown-and-translation-approval-additions-e1814ce5baab
Unhandled rejection TestError: It must return 90 - Expected: 90, instead got: 10 Unhandled rejection TestError: It must return 90 - Expected: 90, instead got: 10
misleading description
Misleading how?
Hello !
testShuffledInput It must work for a shuffled input expected:<1> but was:<0
testFirstElementMissing It must return 1 for a sequence missing the first element expected:<1> but was:<0>
This comment has been hidden.
1
if invalid input, but also return1
if valid input where1
is missing)Fixed the first point, although the others are still valid
This comment has been hidden.
all, except 1 test fail. all test listed below task code successfully passed, but during submit it doesn't work well.
It must return 1 for an invalid sequence - Expected: 1, instead got: 0
wtf is wrong?
I ran the sample test, my code passed all. But when I attempted the solution, all but one failed. I discovered that the one that failed is the number 8 in the sample test... "2 1 4 3 a" . but it didn't give any error in the sample test.
The random test cases are terrible and contradict some of the other cases
You should change the random test cases to test for missing numbers as well. All of them test for non-numeric characters at the moment which should also be changed to different types of non-numeric charactesr. Right now, it only uses 'a'.
The first suggestion would test the code for finding missing numbers, and the second one would test for whatever code checks for non-numerics.
I'm getting this error: "It must return 90 - Expected: 90, instead got: 2". Is there any chance to see the test input? All other tests pass, even the random ones. Thanks.
It's not an "issue" of the kata, more a question;-)...
Thanks, I didn't remember that was a thing :)
All tests pass for me other than the final "basic test", which throws this error: 'It must return 90 - Expected: 90, instead got: 2'. It is unclear to me which condition is not being satisfied here. If I could see the argument for this test, it would certainly help. Please note that I have read the question and comments above to which I am replying. Unfortunately, I do not understand how the response to this question was helpful in identifying why the test does not pass. Can anyone please explain smile67's response a bit further? Any help here would be much appreciated.
On hitting "attempt," I'm getting the same error for the final test: "It must return 90 - Expected: 90, instead got: 2." Like smiles, I'd love to know why or what array is being passed in.
couple of tips which you might get helpful :smile:
if you want to see what input was passed in , use
console.log(input)
if you want to know what type of input was passed in
console.log(typeof(input))
terrific--thank you!
You need to convert string to integer in your sort. Otherwise, it will sort like 1, 10, 100, 101, 102, 2, etc. This will give you the "2" error.
what is wrong if only 1 error:
test3Digitnumbers It must return 90 expected:<90> but was:<1>
?
your code at least fails that test, so then the testing just stops. (there are probably more tests which your code will fail). so, just fix the code to pass that test and you will possibly be able to pass other, maybe even all other tests... but that remains to be seen. best of luck!
But my code works well. Where I need to search bug ?
read the error messages
There needs to be tests for unsorted number sequences, as I just had my mind blown while looking at other's final code who just iterated through the number sequence with no sorting. :)
It's frustrating when a problem doesn't test all its stated requirements.
Such tests are available in all languages as of now! Ex:
2 6 4 5 3
I seem to have some trouble understanding the failing test cases:
testFirstElementMissing -> "It must return 1 for a sequence missing the first element". What does that mean? The description clearly states that it should return 1 only when the sequence is invalid (it contains a string with non numeric character). Also, what is the "the first element"? If the sequence is missing the first element, does that mean it is "empty"? Because the description says we should return 0 in that case.
testShuffledInput -> "It must work for a shuffled input (expected 1)". I don't understand this either. You have written a test that checks if we can handle shuffled (I assume this means unsorted) input. However, you have written this test so that it expects 1, a result which is reserved for a sequence containing invalid characters. Surely if that is the expected result, you can't expect the input to be sortable?
The description clearly states: " numbers starting with 1". So, if the list does not start with 1, but is ordered anyhow, then the smallest missing number is 1.
It's the same result as for invalid lists, but that's as requested.
This comment has been hidden.
thanks! :)
@suuuzi
,No problem.
I voted 6 kyu , what do you guys think ?
Fun kata by the way.
What about some 2 digit numbers as input?
Also description says "Sequence may be shuffled" does not make sense to me. Check dictionary meaning of sequence
Hi,
Description updated!
the random testing is broken.
Testing for 16 9 4 20 18 12 8 1 7 14 3 13 10 2 17 5 19 6 15 21 It should work for random tests too: 1 should equal 11
UPD: I was converting string to numbers. So this is my issu Nevertheless the description can be more clear for this case. Or use in random test non numeric characters.
Hi!
I've added some non numeric characters in random tests. Thanks for the feedback!
Instructions could have mentioned case in which the missing number is the first of the sequence. Otherwise, everything looks good.
Hi,
I've updated the example test cases to include the test "It must return 1 for a sequence missing the first element"
The description is clearly lacking, same goes for test cases. And while not a very difficult problem I don't think it should be tagged as #fundamentals
Hi,
Description and test cases updated. Can you suggest a better tag?
Thanks!
Only recently did I realize that you have to choose a "main" tag from a short list. Thus "fundamentals" is probably the best, given limited choices, so please disregard the tag part of the comment and thanks for updating description/test cases.
!
please, describe the issue :(
Default tests weren't good enough. Maybe add a reversed list and a couple of other cases.
Hi,
Test cases updated!
This is very similar to http://www.codewars.com/kata/55eea63119278d571d00006a and while there are differences (this one deals with strings, unique numbers, and possibly invalid arguments; that one deals with lists of ints and possibly duplicate numbers), I wonder if they are enough to warrant two separate katas.
Hi,
Is this really an issue? I can't merge them because I didn't create the other Kata. Mine was created first, though.
guys my code is running perfectly on IDLe....but the code is incorrect as per this code analyser...can anyone help i did on python
Should non valid squences really be part of this kata? It add just an ugly if statement, don't really see the point.
non valid sequences forces you to validate the input which is good coding practice :)
I agree that validating input is a good coding practice, but in this kata it seems a bit random. You can pass the tests while your code can still except invalid squences, for instance containing floats which will silently be casted to ints. An talking about good coding practices, if you want write an algo that should operate on a list of numbers, why not accept only a list in the first place? Converting a string to a valid squence of ints should be a seperate function.
I really enjoyed this kata, but I would add some examples of invalid sequences in the description. E.g.
find_missing_number("1 a 2 5") # returns 1, because it contains a non numeric character
Done!
The description should mention something about the sequence not actually being sequential in the final tests.
Hi,
Test cases updated!
Non-sequential sequence is a non-sense. Should say either "bag" or "set" of symbols as far as some random combination of numbers does not make a sequence automatically.
Kata needs more specific explanation, e.g. what is invalid sequence
is a string with non numeric character. description updated, please check if it's clearer. thanks!
The description could be a bit clearer.
please check if it's clearer. thanks!
Yup, looks better.
Needs to be more clear on what random strings and shuffled strings are.
please check if it's clearer. thanks!
Problem definition is not complete. Invalid sequence is not defined. Test cases are not comprehensive enough.I can pass the tests but when I submit my code fails and I do not know why.
invalid sequence is a string with non numeric character. description updated, please check if it's clearer. thanks!
Can anyone define "invalid sequence"?
is a string with non numeric character. description updated, please check if it's clearer. thanks!
Needs to provide a test case for numbers greater than single digit since that is part of the actual tests when submitted.
Done!
Liked that it made me think about manipulating different types like strings lists and sets. Didn't understand while my solution was failing with a ValueError - and still don't. Assume it was due to trying to cast a string as an Int but couldn't see that in the displayed test cases - maybe I missed it. If that is the case definitely add a test case in the bottom right to account for this. Overall could do with a bit of improvement but nice challenge.
This comment has been hidden.
C# translation kumited
description is too vague!
Instructions not entirely clear
description updated, please check if it's clearer. thanks!
I am trying to solve this kata in JavaScript and i got this error: "It must return 1 for a sequence missing the first element - Expected: 1, instead got: 0". What exactly is meant as the first element?
The sequence should start with
1
. You should only return0
if the sequence is not broken! This means the sequence would look like"1 2 3 4"
.They mean that the first element of the input string, when converted into an array, is not 1. All valid input strings have to have a 1 (so "4 1 3" and "3 1 2 5" are OK, but not "2 4 5").
All lists are expected to start with element "1", so if the list is (2,3,4) then it is invalid.
description updated, please check if it's clearer. thanks!
Not a clear definition of "invalid sequence"
is a string with non numeric character. description updated, please check if it's clearer. thanks!
I was confused what 'invalid sequence' was. I would add an example of invalid sequence and a test for invalid sequence to basic tests.
description and test cases updated!
I don't know what it means when it's asking for an invalid sequence.
is a string with non numeric character. description updated, please check if it's clearer. thanks!
Vague description.
description updated, please check if it's clearer. thanks!
it is not clear in the description what an invalid sequence is. Is it one that jumps by more than 1 integer value or one with non-integer characters? This should be more explicit in the description.
is a string with non numeric character. description updated, please check if it's clearer. thanks!
It wasn't immediatly obvious to me what a shuffled sequence meant.
im in ruby
what defines an 'invalid sequence'
is a string with non numeric character.
The description is very short. It is hard to know what exactly end when should You return. There was no mention about validating strings (that it is possible other things then spaces and numbers and empty strings). Please make description a little bit more descriptive:)
description updated, please check if it's clearer. thanks!
The description should be talking about "a shuffled set of numbers" right from the start rather than just "a sequence of numbers". It's confusing to read about shuffling only in the last sentence. There should also be a test case to verify/falsify the handling of shuffled sequences.
The description is unclear about what is a legal input and what is not.
Most of the problems have already been mentioned: unclear problem description, including unclear input and fringe cases
Hi,
Description and test cases updated!
It wasn't descriptive enough. I didn't know to expect the input to be an array until after I passed many tests.
Another issue is that I wasn't sure if I was looking for interruptions in sequences. Knowing that it can be shuffled made sense once I started seeing tests (only after hitting Submit) having a jumble on numbers. That's when I realized I'm supposed to reorder them.
I have no idea how to rate this Kata on difficulty because depending on what it is asking for, the difficulty varies. You can see how the vagueness can make that even more difficult.
Hi,
Description and test cases updated!
I keep getting this error even though all the tests pass:
ValueError: invalid literal for int() with base 10: '_______'
I can't even refer back to which line the error is being thrown
What language?
Python
What I like to do to troubleshoot in this case is print out the input. Try putting "print sequence" (without quotes) at the beginning of your function. If you're still unsure what the problem is, just reply back to me.
This comment has been hidden.
This comment has been hidden.
Makes no mention of invalid input in the description.
I didn't kwow that sequence could be not only string but array, as well
This comment has been hidden.
I think the description should include that if a sequence starts with 2, the missing number is 1! The missing number could have been the +1 of the last number (according to your random test)
Lacks tests like "1 2 a3a 5" (should yield 1, as sequence is invalid)
the unsorted random numbers required for the code to be changed from the orignal question
The description is unclear. How order of the sequence affects... what is an invalid sequence and so on ( Thnx otherwise, it was rather interesting.
The description is slightly unclear (not bad but could have a bit more), nothing is said about the order of the sequence, which leaves you wondering if that factors in. Also, an invalid sequence is not defined, it might be worth mentioning what invalid means... at first I thought it could relate to order, or possibly multiple missing items or something.
Easy once I knew what to do.
This comment has been hidden.
description and test cases updated, please check if it's better. thanks!
This comment has been hidden.
description updated, please check if it's clearer. when is missing more than one number, should return the lowest. e.g. missing 3, 4 and 6 in your sequence, so should return 3. thanks!
This comment has been hidden.
description updated, please check if it's clearer. when is missing more than one number, should return the lowest. e.g. missing 3 and 6 in your sequence, so should return 3. thanks!
Tests break with strict mode.
Add a few more tests for randomized numbers and a return of zero if the numbers are already sorted.
This case fits description and will brake a lot of exisitng solutions. Case of shuffling numbers is not covered. I think below test case will cover it.
@Test public void test5() { assertEquals("", 2, new BrokenSequence().findMissingNumber("5 3 4 1")); }
It is not clear what a invalid case is pls be more specific does it mean the string contains more spaces or special char or just char....
Guys, I'd finally reached an impasse: I can't get throw the 7th test of submiting. Does anybody know what kind of sequence it has as an input for Java vercion of kata?
I am far from proficient with Java, but I assume it is the same issue with Juan and niklaus discussed below: your code fails on an invalid sequence - ie: a sequence with not only spaces and numbers.
Try to consider that possibility and it should work just fine :)
Thanks! You're right, I didn't consider that possibility.
My pleasure :)
description updated, please check if it's clearer. thanks!
This comment has been hidden.
See my reply to JuanEiros just a bit under yours :)
This comment has been hidden.
I enjoyed this kata. My only advice would be to add a few more relevant categories so that it can be found easier ;)
If you want to suggest some, I would gladly consider them for an integration :)
OP left the building, plus categories (tags presumably) are not mentioned precisely , closing
This comment has been hidden.
The problem is that you should first of all check to see if the sequence is invalid (=has invalid characters); one of the text cases deliberately give you something like '____' just to test that.
I am not the one who wrote the Python version, but basically any version works that way on purpose.
I hope that was clear enough and the issue can be considered fixed :)
This comment has been hidden.
This comment has been hidden.
Thanks for your feed and description integrated with your suggestion: let me know if the issue is now fixed :)
Looks done.
marking as resolved.
This comment has been hidden.
Test edited for more clarity, let me know if now it is ok with you :)
Much clearer!
The description states that the sequences start with 1, but the tests validate against sequences not starting with 1.
This comment has been hidden.
Done! Thanks.
Random tests aren't working properly. It's currently asking me to return 0 for an invalid sequence, which the instructions claim should only be returned for an unbroken sequence.
Could you tell us in which language and what was the input that created this problem? Also, consider that the sequences may be shuffled, so for example "4 3 1 5 2" returns 0.
description updated, please check if it's clearer. thanks!
Does it really need to be a string? That just puts another layer on top of it. Isn't an array or a list (depending on the language) sufficient?
I thought about that too, but I choose to respect the original author setting as much as possible, plus a little one-line parsing won't hurt anyone: I like to see this like you have to run 10km for a training and you are asked to sprint for the first 100m.
Of course, just personal idea, suuuzi will have the last word on it.
P.S.: can you visualize the "+" button to translate katas today? It does not load to me...
@GiacomoSorbi: It worked fine three hours ago, but it only loads if you already solved the kata. By the way, I've prepared a mini tutorial for translations. It's rather incomplete, but I guess it's easier than to write the same text over and over again. Feel free to edit it :).
Curious: now it seems fixed, but before I only got it for already APPROVED katas, not any of the beta katas, be them solved or not.
And curious again, I always get the icons in the center of the header, while in your tutorial they seem right aligned by default.
The tutorial right now seems pretty complete, it may just miss edge cases (like when you are unable to merge translations), but imho that should be dealt at the source, with us translators taking extra care about how to avoid such an issue.
[And again I find your comment by chance, manually checking back, as notifications seem to be as random as usual, sigh...]
Actually, I cut that off. It's usually centered, I just didn't want the graphics to be too wide ^^".
You don't have a top-level comment. You get notifications for four (?) days only if you have a top-level comment.
Too late to enforce such changes as it will invalidate all solutions and languages
Don't be so cruel !
Too many invalid things ! Even in the description :
What must an invalid sentence return ?
(Ok, those sentences are not really invalid but you should admit there're not very very clear)
And Grazie mille for the translation !
Pardon, I wrote it wrong the first time, tried to update, but then something failed (and even now it is putting a lot to save minimal changes); now it is correct with:
An invalid sequence must return 1, an already complete sequence must return 0.
.Sorrry for the inconvenience and prego, non c'è di che ;)
P.S.: can you see the "+" button to translate katas, now? Today CW is running quite slow and I miss this core option T_T.Edit: this now seems to have been fixed.I would suggest to new extra sequences to test:
1 2 3 4 55
and a string with no numbers and spaces_______
Edit: Now it covers. Should return the lowest missing number.
the instructions need to be a little more desciptive as it pertains to of the string is empty or if it starts with something other than a 1
You forgot to say that the sequence increments by 1.
Fixed. Thanks!
Now that the
n
is gone from the provided code, you could get rid ofN=5
in the description.You have a sequence of positive numbers starting with 1, but one number is missing! Find out the missing number. If the sequence is not broken, you should return 0.
Examples
Fixed. Thanks!
This comment has been hidden.
Done, thanks!
State that 0 should be returned when the passed string is empty.
Done. Thanks for the feedback!
Two minor issues:
0
if the sequence is not broken.n
is not necessary to solve the problem and I think it makes the description more confusing.Consider getting rid of that parameter and update the description with something like:
You have a sequence of positive numbers starting with 1, but one number is missing! Find out the missing number.
Fixed. Thanks for the feedback!
This comment has been hidden.
What n parameter is for?
I changed the description and the problem. Is it better now?
Thanks for the feedback.