Originally posted by Campbell: return fruminous && !uffish && manxome ? BANDERSNATCH : JUBJUB_BIRD;
I think the solution provided by Ritchie will fail for the case: fruminous = TRUE && uffish = FALSE && manxome = FALSE as it would give JUBJUB_BIRD whereas it should give BANDERSNATCH.
I agree with Rob's solution. That's cool Rob. Please tell me. How did you get the solution? How should we approach such questions? :roll: After looking at your solution it seems to be correct. But really i had no clue when i first looked at the question.
[Steve]: i would concur, but then again if this was for an interview i would shy away from the ? : as many folks don't like using this construct.
Whereas many others people prefer it; that can go either way. For an interview I would offer both solutions, and make clear that I was willing to code in either style if there was a local style guide to follow. Left to my own devices though, I'd definitely favor the ternary operator.
Joined: Mar 05, 2008
[Harvinder]: I agree with Rob's solution. That's cool Rob. Please tell me. How did you get the solution? How should we approach such questions? After looking at your solution it seems to be correct. But really i had no clue when i first looked at the question.
Obviously I'm not Rob, but one way to approach this would be to notice that since there are only three boolean inputs, there are only eight possible combinations of values. Make a table and see what happens for each value combination:
Once you complete this, it may well be possible to see a simple pattern in the results which is easy to describe with a formula like what Rob gave.
Joined: Jun 10, 2008
Thanks Mike for the prompt answer. Earlier i had thought that it was some trick question. But after some time i did end up following the approach suggested by you. I wonder if Rob did it that way or not?