Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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 usingmin
,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 themin
,max
variable assignments toif
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).
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.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Very good solution, very concize and easy to read, well done.
Great solution. Clear and conscise, but not to the point of being obtuse.
by far the best solution !