Ad
  • Custom User Avatar

    issue , in testing it gives 5 instead of -1 , my machine it work perfectly

  • Default User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    The OP hasn't responded for a week.

    So, do you want me to change the specs of the description or not?

  • Default User Avatar

    And checking for Nothing isn't any different from checking for -1.

    Except that there's are a monad instance for Maybe, if let, ?? and things like that, but not for -1.

    If, at the end of the kata, you find yourself returning maybe (-1) $ intermediate value, the magic value should have been Nothing.

    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.

    Lots of times you see Nothing and Just used directly in different branches of an if equivalent.

    Oh yeah, lots of times you use if, so let's not include case in the language at all (Python)... At least that was supposed to be for simplicity; nils and Nothings are already there, for simplicity as well, even if a different kind thereof. Is it even that frequent anyway?

    An example: imagine a result is...

    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 or minBound for minimum ([] :: [Int]) depending on how it's going to be used), but probably not when an index, non-negative by definition, becomes negative.

  • Custom User Avatar

    Sometimes -1 results naturally from a-b or as the result of a loop counter counting down. It's magic, but no less magic than Nothing. And checking for Nothing 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 using Nothing 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 been Nothing. But sometimes it's the other way around. Lots of times you see Nothing and Just used directly in different branches of an if 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.

  • Default User Avatar

    The thing is that that any concise functional solution is going to be like solutions() || -1 instead of solution() 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.

  • Custom User Avatar

    Get him to approve them first; it should only require changing a single 1 to a 0 per language afterwards. Or get him to pay you. :P

    Sure, it's work. ( Sorry! ) In this case, I think it makes sense for the problem though.

  • Custom User Avatar

    But then we'd have to change very single language - including my pending ones.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Fixed. The issue was only in JS and Ruby - I based all my translations off of Haskell.

  • Custom User Avatar

    Cool, more than happy to fix. I ported the JS tests as closely as possible so that's probably where it got introduced.

  • Custom User Avatar

    ( JS, possibly others, not Haskell )

    Given the scrollY integer (always non-negative) and an array of non-negative integers (with at least one element)

    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 )

  • Custom User Avatar

    Given the scrollY integer (always non-negative) and an array of non-negative integers (with at least one element),

    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.

  • Custom User Avatar

    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...