Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
issue , in testing it gives 5 instead of -1 , my machine it work perfectly
Your Kata still has errors on random tests. For example:
int n=757;
std::vector a{282, 89, 39, 335, 123};
Answer is 4, yor answer is -1.
Without author clarification, my preference would be to have the tests in line with the spec as written. You don't unintentionally write "won't be empty"; you might very well write a buggy random generator.
Changing the spec ( on an approved kata, with the risk of invalidating up to
370
solutions ) is for the author, and noone else, no matter how much real world sense the modified spec makes, I think.Isn't that also the option with the least work, incidentally?
With author consent, my preferred option would be to change the spec. Because it makes real world sense.
The OP hasn't responded for a week.
So, do you want me to change the specs of the description or not?
Except that there's are a monad instance for
Maybe
,if let
,??
and things like that, but not for-1
.Which is exactly what I had to do for this kata in Clojure. And
Nothing
is not a magic value, it's not an arbitrary choice, while-1
isn't better than-42
in 99% of cases.Oh yeah, lots of times you use
if
, so let's not includecase
in the language at all (Python)... At least that was supposed to be for simplicity;nil
s andNothing
s are already there, for simplicity as well, even if a different kind thereof. Is it even that frequent anyway?First, why would you want the result to be
-1
anyway? It only shifted the question to a different place in code.Second, there can be multiple valid choices sometimes (maybe like either
Nothing
orminBound
forminimum ([] :: [Int])
depending on how it's going to be used), but probably not when an index, non-negative by definition, becomes negative.Sometimes
-1
results naturally froma-b
or as the result of a loop counter counting down. It's magic, but no less magic thanNothing
. And checking forNothing
isn't any different from checking for-1
.It looks more idiomatic, but that's just a convention as well; it only helps if native code will help you working with the magic value, like JS does with
array[-1] = undefined
or Haskell with monadic code for usingNothing
as a magic value. Sometimes code can very well be written with a different magic value.If, at the end of the kata, you find yourself returning
maybe (-1) $ intermediate value
, the magic value should have beenNothing
. But sometimes it's the other way around. Lots of times you seeNothing
andJust
used directly in different branches of anif
equivalent. There, it's rather arbitrary.Sometimes, it's a bad idea. Sometimes, it's just an encoding. Sometimes something comes naturally. That may or may not be
Nothing
.The thing is that that any concise functional solution is going to be like
solutions() || -1
instead ofsolution()
and callers will have to do extra steps to check it too. In languages where-1
isn't normally used for this purpose (Clojure, Ruby...)-1
is just a random magic number.Get him to approve them first; it should only require changing a single
1
to a0
per language afterwards. Or get him to pay you. :PSure, it's work. ( Sorry! ) In this case, I think it makes sense for the problem though.
But then we'd have to change very single language - including my pending ones.
Thanks.
I would like to hear OP's opinion on this as well actually. Changing the spec is a viable option; an empty array would encode a valid - empty - website.
Fixed. The issue was only in JS and Ruby - I based all my translations off of Haskell.
Cool, more than happy to fix. I ported the JS tests as closely as possible so that's probably where it got introduced.
( JS, possibly others, not Haskell )
The random generator does not respect this. Empty
sizes
are out of spec.Please fix this for all applicable languages.
The lazy alternative is to specify that the array can be empty. This probably won't affect the logic of solutions and is a valid representation of an empty website. I don't know why that wasn't specified in the first place. But ATM, it is not, and tests are wrong.
If you decide to change the specs, I will need to update Haskell, because it does adhere to the specs as they currently are. ( It's the smallest possible fix; don't worry you're making work for me. :P )
The random test generator does not implement this correctly. Empty
sizes
are out of spec.Please fix this.
ETA: The JS original seems to have the same bug. Depending on the way the issue at the top is resolved, action may or may not be necessary.
The kata specifies that the array of non-negative integers always exists, and always has at least one element.
Do you mean to say the tests don't always generate such arrays? ( That would be an issue. ) Otherwise, what do you mean to say?
Loading more items...