News for hackers. Stuff that matters.
Re:Array Iteration Interview Problem by mdj on Wednesday August 01, 2012 @08:52PM (#4326613)
The OP's implementation wastes cycles in the n == 0 case because the statement `if (count == n)` is unnecessary.
Re:Array Iteration Interview Problem by ben0x539 on Wednesday August 01, 2012 @08:55PM (#4326622)
And surely the `count++;` statement.

I don't see an obvious solution that doesn't "unroll" the three cases and doesn't waste any cycles, but maybe that is why I don't work at OP's company. ;)

Re:Array Iteration Interview Problem by jazzychad on Wednesday August 01, 2012 @09:00PM (#4326644)
yes, the count++ (and count variable itself) are unnecessary since I could just text n against 0 and then break. good catch.
Re:Array Iteration Interview Problem by ben0x539 on Wednesday August 01, 2012 @09:05PM (#4326663)
But decrementing n would still cost you cycles in the case where n was given as 0 that you wouldn't need if you had separated out that case, wouldn't it?
Re:Array Iteration Interview Problem by jazzychad on Wednesday August 01, 2012 @09:10PM (#4326673)
yes, that's right. Then it becomes a tradeoff of cycles and code-readability since I would have to special case for 0.
Re:Array Iteration Interview Problem by jazzychad on Wednesday August 01, 2012 @08:54PM (#4326618)
cool, I'm genuinely curious how I could save those cycles without adding more elsewhere?