mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Hi guys, just wanted input on how you would go about answering riddle/analytical questions. I have these in particular:

How many runs up a ladder an egg can be dropped from, before it will break on the surface (using the least number of attempts)

How to determine the same thing using the least number of eggs?

Given a string of open/close brackets of all 3 types: (, {, [, ), }, ], how to determine that the open/close brackets are in the correct mathematical sequence, e.g ({[]{}()})

Last edited by pouncer; 19/01/11 09:22 PM.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Are we doing your homework for you, now?

I'll bite:
1) Binary search,
2) Attempts are eggs, so binary search, unless I misunderstood
3) Write a parser / state machine.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
2) start at the lowest rung and move up one until the egg breaks


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Start at the top and the egg breaks on the first attempt.

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: RoCk

Start at the top and the egg breaks on the first attempt.


but you're not trying to minimize attempts in part 2 of the question. this might be a suitable answer for part 1 if the question were phrased slightly differently. the question is asking, with little if any ambiguity, for the lowest rung from which an egg can be dropped without breaking. if this were a lateral thinking question or silly riddle then we might as well say the top rung is the answer since we could turn the ladder upside down and drop it from that rung :P intentionally misinterpreting these questions can lead to all kinds of valid answers.

i'm fairly sure argv's solution to 1) and mine to 2) are correct using the most sensible interpretation of the problem.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
But your answer for 2) seems "too obvious". It's not much of a riddle if there's absolutely no logical trick involved.

My assumption for #2 is that "using" an egg == dropping it, regardless of whether it breaks or not. That is, eggs are not reused. I see that as a reasonable assumption (I'd probably ask for clarification from the interviewer).


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
if an egg were equivalent to an attempt then the 2nd part of the question would be asking the same as the 1st part. in order for it to sensibly follow the first, the implication must be that it is now ok to re-use an egg if it didn't break (assuming, of course, that an egg doesn't get weaker once it's dropped!)


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Considering most eggs will probably break from the first or second rung if not protected in some way, it's not really a good riddle. They would have been better off using something more sturdy. But oh well. I agree that starting at the bottom and going up using the least number of eggs because I also feel that "use" means "breaking". Then again, if they meant breaking, they'd have said so.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard