Ad
  • Custom User Avatar

    You missed the point I was trying to make. It doesn't matter how you write it, with an if block, or with a ternary, or using min, max, the performance difference is miniscule between all of these methods. If someone sat you down in front of this solution and told you to optimize it, and you changed the min, max variable assignments to if blocks, then you would have failed the task. Nobody cares that one of these is a few hundred microseconds faster than any of the other ones.

    Your claim that changing the code to what you've written above will "shave off a third of the execution time" is only true for a small range of (a..b) due to the speed of the rest of the solution. In other words, if you run the original solution at the top of the page with very large inputs (like 0, int.MaxValue / 2) and compare it to one where you've replaced the variable assignments with your ternary expressions, your ternary assignment one no longer shaves off a third of the execution time (It will likely only shave off like .00002% of the execution time, if anything).

  • Custom User Avatar

    It's not the fact that it's ternary, the same would be true if it were an if/else block. And writing the ternarys or if/else is in no way a waste of time.

    That being said, I need to dissect and understand your code. It is literally more than 200,000,000 times faster than mine (tested for one iteration, with (0, int.MaxValue / 2) as parameters...I stand humbled.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    Very good solution, very concize and easy to read, well done.

  • Custom User Avatar

    Great solution. Clear and conscise, but not to the point of being obtuse.

  • Custom User Avatar