Ad
  • Custom User Avatar

    well i would advise to studdy Riemman Sums then, you'll understand where the code comes from ;)

  • Custom User Avatar

    Use spoiler flag next time, please.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Fair enough. Picking your battles is also a key part of the review process ;)

  • Custom User Avatar

    Then you're just literally "bitching about things that are irrelevant", you know.

    (I decided to use blunter words here because, well, comment section are supposed to inform people about the various advantages/disadvantages of a solution, not for people to write pages of rants complaining why they don't like a solution. Literally nobody gives a damn about that, so get over it and accept that you're salty and biased. Doesn't stop people doing this every day though)

  • Custom User Avatar

    This absolutely would pass code review, because it's a math solution to a math problem. It is not a business/logic problem so it does not require that kind of solution. Should it have a comment that points to the theorem? Absolutely and that's the only review comment it should receive.

  • Default User Avatar

    Prematured optimization...!? This is non sense...

    And it's totally up to you to choose to NOT improve your skills by sticking to "bad algos" believing that's the right choice.

  • Custom User Avatar

    I don't think anyone that pulls out the "premature optimization" card when talking about good code is trying to make much sense.

    Anyways, as I've always said before, "complaining about solutions you don't understand/you don't like" is... bad? That's like saying, "I can't break this crypto so it must be unbreakable". Also, since this snippet does what it does exactly, there's nothing about "unmaintainable", "unreadable" or something; they're strawmen since you don't have to maintain or read it. Unless you want to know why it works, but then that's what comments are for, and not the code itself. Code does not, and will not submit to dumb people by dumbifying itself, it doesn't work that way.

  • Default User Avatar

    I agree about premature optimization in general and that asymptotic complexity doesn't really matter as long as a given task is done in given time.
    However, I don't really think that this solution is a case of premature optimization. At least that wasn't my goal, it's just the first thing that came to my mind.
    Another thing is that Codewars isn't really a place where people normally comment their code. So it's like: would everyone understand what a solution does--not why it returns what it should, but how it works at lower level? Usually yes. Then if it had some comments, it would probably be ready for production.

  • Default User Avatar

    Yet this problem, and many others on here, can be solved with very readable Linq expressions with the advantage that knowing Linq is applicable across many problem domains

    Yet this problem, and many others on here, can be solved with very readable mathematical expressions with the advantage that knowing middle school mathematics is applicable across many problem domains.

  • Default User Avatar

    so, you're saying that one should use loops or their Linq equivalent to achieve in O(n) what can be done in O(1) using solutions just like this one...? I rather believe that your proposition shouldn't pass code review either... :p

    Sure, this solution would benefit from comments. But don't bash it because you do not understand what's going on just by reading it. Add comments to it and it becomes the ideal solution. Without loops or Linq.