Ad
  • Custom User Avatar

    Speak for yourself. I found it valuable as it forced me to delve into Reflection. I learned something along the way.

    Also, as Grandpaw liked to say: "If you ain't got nothin' nice t'say, 'tis better ain't t'say nothin' at all."

    Cheers.

  • Custom User Avatar

    I blame YouTube for that.
    Hence mob-upvoting the refactoring of a brute force solution into a method that replicates the behavior of native Java, except with higher CPU overhead.
    This site offers a wonderful chance to actually learn a new language and use everything it has to offer, but not everyone is willing to take on the challenge.
    I say they're missing out, but to each their own.

  • Custom User Avatar

    Best pratices doesn't mean most faster or efficient. Good balance (performance, readability, maintainability) is the key of best pratices: so it includes good readability.

  • Custom User Avatar

    As for why so many people marked it as "Best Practice"... maybe they liked the variable names and spacing between lines?! Just kidding. I'm guessing they just didn't realize there was a better way. Or they exhibited mob behaviour - once it has a few upvotes others upvote to go with the crowd.

  • Custom User Avatar

    @sheriv, it's not one iteration. For each index he's checking he sums up all the numbers on the left and all the numbers on the right. He's forcing the CPU to do the same calculations over and over, and to solve this it's unnecessary. For example if you are at an index and already know the left and right sums at that point, you only need to remove one element and add one element to check the neighbouring index - but the solution above has the program recalculate the entire sum on both sides. It's functional but it's not elegant or efficient.

  • Custom User Avatar

    I think the best solution gives us O(n) complexity since there'is only one iteration.

  • Custom User Avatar

    I don't think that this is as difficult as coming up with a formula of relativity theory. Others have decided that this kata is worth 4 kyu, which means that, yes, it's difficult, but not that difficult. As for the inverse function, it has a precise mathematical definition: If f is a function from the non-negative integers to the non-negative integers such that f is one-to-one and onto, then f has an inverse g such that if f(x) = y then g(y) = x. Since I'm telling you that the mystery function has an inverse, I am implicitely telling you that it is one-to-one and onto.

  • Custom User Avatar

    Not even easy to read. Just bad solution... ;)

  • Custom User Avatar

    I'm always wondering why people consider solutions like this best practice. Easy to read and understand: Yes. Best practice: Never ever.