Well put. I couldn't agree with you more.;)Quote:
Originally Posted by JasonD
Printable View
Well put. I couldn't agree with you more.;)Quote:
Originally Posted by JasonD
Yes, it's a strange interview question.
I found the first solution in the first minute, then I thought 'what a pointless exercise' and went off and did something more interesting instead. ;)
I finally got all three! I'll admit that it helped when the details of the problem were explained... as it hinted at where I should look for the third solution (which was -i<n for me).
Three, it is very tricky question
new here, found this fun problem through google.
i+n was definitely the hardest one! remembering that the loop condition is only false when negative helped =)
What about
int i, n =-20;
?
Took about 5 minutes. I never would have thought of n+1. More than 3 solutions, I guess. : )
Got all three. Surprisingly I don't think the third solution took me as long as the second solution. :blush:
If n is -20, i=0 will never be less than n.
Interestingly, since I didn’t want to read past the first few posts, I did not realize that I played this game five years ago, and accidentally found (again) all three solutions. Again without timing; about 10 minutes, I guess.
Do I get a double bonus?
There are four so far... anyone want to see them
for (i=0; i+n; i--)
for (i=0; i<n; n--)
for (i=0;-i<n; i--)
for (i=0;~i<n; i--)
Neat question, not a very good introduction. Once someone finds three, they think they are a genius. Did someone find another?
By the way, the unary NOT is replacing a space (" ") just like the negative symbol
My bad, dumb, should've read the posts about the unary operator. Silly oversight, great problem for the class.
What's wrong with this one?
for (i=40; i<n; i--)
I'm not trying to be a smart ***, but this is not insertion?
for (i=0;-i<n; i--)
Or in this case, we substitute default-hidden '+' ?
Don't mean to show off but it took maybe 20 seconds. I can't imagine no one has got that on his quiz or whatever since 1999 that's absurd.