Ad
  • Custom User Avatar

    Jump overflow and underflow semantics should definitely be specified in the problem, omitting them and then let people try to guess does not make a good problem, but a bad spec.

    (For those stuck: Overflow should make your program terminate, not throw exception. Underflow is not relevant (I think), but I made it just stop at the first instruction.)

  • Custom User Avatar

    Thank you very much!

  • Custom User Avatar

    One-liners tend to have that side-effect... And it probably is the case here.

    However, remember that «Premature optimization is the root of all evil»: If I would have to create a big bunch of variables to avoid recalculations, the code would become unreadable quite quick.

    Furthermore, nothing is won when you replace two calculations with an assignment and a calculation! You only start to win something with three or more recalculations avoided!

  • Custom User Avatar
  • Custom User Avatar

    And I would never write this in production code!

    A simple refactoring into a helper function would make this much more digestible!
    Alas, the "one-liner factor" was too appealing... :)

  • Custom User Avatar

    I don't know if this has been updated, but I have been able to solve this problem. Perhaps you are summing number by number? There are more efficient ways!

  • Custom User Avatar