You are on page 1of 32

Remember Me

Username

Forgot your
password?

Log in

Password

Create an account
Search

Home
Exams
Study guides
Jobs
Forums
Books
Who we are
Contact Us

Puzzles as Programmer Interview Question


User Rating:
Poor

/0
Best Rate

Study guides - Progammer Interview QuestionType


Article Index
Puzzles as Programmer Interview Question
Cutting a cake into 8 pieces
Minimum guesses to find a # from 1 to 1000
three-switches-three-bulbs
Lockers Puzzle
8 Pennies Find Lightest 7 equal
Measure weight of an elephant with no scale
Measure 4 liters
25 horses 5 lanes 3 fastest puzzle
Same national champion 65 year span
Rope Bridge Puzzle Four People One Flashlight
8 marbles puzzle find heaviest
8 marbles riddle generalize solution
2 Fuses Problem Measure 45 Minutes
Train Escape Puzzle 2 boys
All Pages

Puzzles as Interview Questions

Like it or not, puzzles are a big part of interview questions for programmers these days.

Whether they really tell your employer anything revealing about your intelligence is
highly debatable (and highly unlikely in our opinion). But, here we present some
puzzles that weve come across. Just try to have fun with them!

1. You have a birthday cake and have exactly 3 cuts to cut it into 8 equal pieces. How
do you do it?

A: Try figuring this one out on your own as a hint well tell you that youll have to think out of
the box on this one.

The answer: stack the pieces

The correct answer is to cut the cake in quarters (4 pieces) using 2 of the cuts, then stack
all 4 of the pieces and then split all four of the stacked pieces with the third cut.

You might think of this as sort of a trick question, since moving the pieces is
something out of the box but somebody asking this question is probably looking
for that kind of out of the box thinking.

1. Given the numbers 1 to 1000, what is the minimum number [of] guesses needed to
find a specific number if you are given the hint higher or lower for each guess you
make?

A: This may be considered a trick question, since its deceptively easy. Read the question
carefully and youll note that the question asks for the minimum number of guesses. Think
about it someone can guess the right question on their first try right?

So, the answer here would be 1, since it would take only one correct guess to find a specific
number.

Finding the maximum number of guesses

But, what if we wanted to find the maximum number of guesses?

Well, think about this one. What if the number that you have to guess is 1 and you start
guessing from 1,000? Then, if the person who knows the number keeps saying lower, then
you would guess 999,998,9976,5,4,3,2, and finally until you get to 1.

The maximum number of guesses

This means that the maximum number of guesses is 999.

But, you must be saying, thats a stupid answer because no one would take that approach
to guessing unless they were really foolish.

Using Binary Search

The approach most programmers would take is dividing the set of numbers in half and then
working accordingly basically a binary search as it is known in computer science.

So, lets say the number you were trying to guess is a 1. Then, you would start from the
middle of 1,000 which is 500. The person giving you hints would keep saying lower and
you would end up with something like this sequence of numbers:

500, 250, 125, 63, 32, 16, 8, 4, 2, 1

Counting the number of guesses above would give you 10. Another way of arriving at
this estimate would be to take the log base 2 of 1,000 which would also give you
approximately 10. Since you cant possibly have a fraction of a guess, the result of log
base 2 of 1000 should be rounded up to a whole number. Log base 2 of 1000
actually gives 9.965, but we round that up to 10 to get an integer.

1. Suppose that you are standing in a hallway next to 3 light switches, which are all
off. There is another room down the hallway, where there are 3 incandescent light
bulbs each light bulb is operated by one of the switches in the hallway. Because
the light bulbs are in another room, you can not see them since you are standing in
the hallway.
How would you figure out which switch operates which light bulb, if you can only go
the room with the light bulbs one time, and only one time?

A: A lot of times it helps just to state the obvious, so lets do that here:
If a switch is in the on position then the light bulb corresponding to that switch will light up
as well.

Now, given the previous information, can we solve this problem? Well, just think about the
different possibilities. If we have all switches on, then when we go into the attic all the light
bulbs will be on. This tell us nothing about which switch corresponds to which light bulb. If we
have 2 of the switches on, then when we go into the attic, 2 of the light bulbs will be on. This
will tell us that the switch which is in an off position corresponds to the light bulb thats off in
the attic. And if we have 1 switch on (and the other 2 off), then we know which switch
corresponds to the light bulb thats on.

Neither of the last 2 solutions are complete because they only tell us about one of the
switches and the light bulb that it corresponds to. But the problem clearly states that we
need to know about all three of the switches, and which bulb each one corresponds to.

Think outside the box

So its now obvious that we must find some other way of solving the problem. Lets think
outside the box: what else do we know here?

Well, the properties of a switch dont seem to have anything unique to them they are just
either simply on or off.

2. What happens to a light bulb when turned on?

A: What about the light bulbs? Well, we do know that incandescent light bulbs get hot when
they are on this sounds like it might just lead to something useful that can help us. We
know that the longer an incandescent light bulb stays on the hotter it gets.

So, if we turn one switch off after 5 minutes, turn the second one on, and leave the last one
off then what happens? Well, the light bulb corresponding to the first switch will still be warm
(even though its off), the bulb corresponding to the second switch will be on, and the bulb
corresponding to the last switch will be off. This is enough information so that we can go into
the attic only once and figure out which switch belongs to which light bulb.

This question is tricky because it requires thinking somewhat creatively to come up with a
solution. Measuring someones intelligence based on a problem like this is probably not a
good idea whether people stumble open an answer to this is often due to their luck. Unless,
of course, they already knew the answer.

1. You are standing in a school hallway lined with 100 closed lockers. You then open
all 100 lockers. After this, you then close every 2nd locker (so the 2nd, 4th, 6th98th
and 100th are all closed). Then, you go to every third locker and open it if it is closed
or close it if it is open (lets call this toggling the locker for our discussion). You
proceed to toggle every nth locker on pass number n. So, for example, on pass
number 16 you will toggle every 16th locker. After your hundredth pass of the
hallway, in which you toggle only locker number 100, how many lockers are now
open?

In a hall with x lockers, how many lockers remain open after pass number x?

A: This problem can seem intimidating at first. Just drawing a diagram of 100 lockers and
actually toggling each one would not really display any intelligence on your part. In fact, youd
probably look pretty dumb. Clearly, there must be a more intelligent way of solving this
problem since you wouldnt be asked this question if there werent some smarter, more
efficient way of solving this.

Start Out Small

This isnt the type of problem that gets solved just by staring at it and hoping an answer just
comes to you. So, a good idea is to try some different numbers (much smaller than 100, of
course), and see if that helps you notice some patterns.

Lets just start by choosing a random locker, and lets determine whether it will end up open

or closed. Lets choose locker # 6.

Lets go through each pass:

Pass # 1: all lockers are opened, including locker # 6


Pass # 2: all even numbered lockers are closed, including locker # 6
Pass # 3: every 3rd locker is toggledso 3, 6, 9, .96, 99. includes locker # 6.
Pass # 4: 4, 8, 12, etc. are all toggled. Excludes #6.
Pass # 5: 5, 10, 15 are all toggled. Excludes # 6 again.
Pass # 6: 6, 12, 18, etc. are all toggled. Includes # 6.

Passes greater than 6: Locker #6 will not be toggled again, since those will all start farther
down the hall.

So, one thing you may notice after running through this example is that locker #6 is only
toggled when the number of the pass (also called x) that you are on is a factor of the # 6
you can see that 1,2, 3, and 6 are all factors of 6. And those are all the passes on which the
locker 6 is toggled the sequence is open, close, open and then close. So, locker # 6 ends
up closed.

Now that sounds like promising information. Since we are dealing with factors here, why not
try a prime number since a prime number only has 2 factors itself and 1. Lets try the
number 13 as our prime number. The factors are 1 and 13 which means that the operations
are open and then close for any pass greater or equal to 13. So, it ends up being closed.

So, we know one thing for sure: that the lockers are only toggled on passes that are factors
of the individual locker number.

Its all about the factors

What else do we know? Well, we know that lockers are closed every 2nd, 4th, 6th, etc. times
they are toggled so if a locker is toggled an even number of times it ends up closed,
otherwise it ends up open. Combining this knowledge with our other knowledge, we can say
that a locker will end up closed if it has an even number of factors, because the number of
times a locker is toggled equals the number of factors. If a locker has an odd # of factors, the
locker will end up being open.

So, this knowledge makes a big difference weve really simplied the problem now all we
need to do is figure out how many numbers between 1 and 100 have an odd # of factors, and
we will have our answer!

First, lets jump into the math to find our answer.


What exactly does it mean when we say that c is a factor of d, for some #s c and d?

Well, it means that c multiplied by some other number b is equal to d. This also means that b
is also a factor of d since multiplication is commutative (c*b = b*c).

So, the number of factors is usually even since factors tend to come in pairs. And an even
number of factors means that the locker will end up being closed.

But, what if the factors are the same numbers if b is equal to c? Then, the number d would
be a perfect square, since b*b would equal d, which would be a perfect square. This would

also mean that we would have an odd number of factors and an odd number of factors would
mean that particular locker will remain open.

Since there arent very many perfect squares between 1 and 100, you can list them out
here they are: 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100 so, exactly 10 lockers will remain
open.

Generalizing the solution

Now, lets generalize the solution so that we have an answer to the original question:

Ifthere are x lockers, the number of open lockers will be the number of perfect

squares between 1 and x (inclusive). To count them, all you need to do is find the
square root of the largest perfect square less than or equal to x. So, the general
solution would be: floor(sqrt(x))

Heres an example to help illustrate this:


If x = 200, then sqrt(200) = 14.142 ..

And because floor(sqrt(200)) = 14,

there will be 14 open lockers.

In an interview situation you may not have been able to easily get to the answer here. But, the

most important thing is that you give it your best shot, and you approach it intelligently!

Here, you should also see the value of breaking the problem down into a more manageable
size, finding a pattern, and then coming up with a solution.

1. You are given 8 pennies, 7 of which weigh exactly the same, but one penny
weighs less than the other 7. You also have a judge scale. Find the one penny that
weighs the least in less than 3 steps.

A: Like most puzzles, the answer to this question is not going to just jump out to you youll
have to break the question down.

We know that a judge scale is used to compare the weights of different things and it tells us if
something on one side is heavier, lighter, or the same weight as whatever is on the other side
of the scale.

Since the question asks us to find the penny that weighs the least in less than 3 steps, that
means that we will need to find the lightest penny in either 1 or 2 steps.

So, lets think of finding the answer to this in 1 step: Really, the only thing we can do is
compare 2 pennies on the scale and if one is lighter than the other than we know that it is the
lightest. But, we would have to be lucky enough to pick the lightest penny to compare, and
theres no way we can do this without just getting plain lucky. So, theres also no way we can
do this in 1 step.

Has to be done in 2 steps

Now, we have to be able to do this in 2 steps so how is this possible? What if we just tried
dividing the 8 pennies into groups? Lets create 2 groups of 3 pennies each, and 1 group of 2
pennies.

Now, lets put the 2 groups of 3 pennies on the scale. What do we know if they are equal?
Well, if theyre equal then the lightest penny must be in the group of 2!

Then, lets take 2 pennies in the group of 2 and compare them to each other. They cant
possibly be equal, so we know that the lighter one is our lightest penny! Bravo we have an
answer in 2 steps.

But, what if when comparing the 2 groups of 3 pennies, it didnt turn out that they were equal?
Well, one of the groups of 3 would be lighter, which means that the lighter penny would be in
that group.

So, we could take 2 pennies out of that group of 3 and compare them. If theyre equal we
know the 3rd penny is the lightest. If one is lighter than the other, then we know that penny is
the lightest. So, again the problem is solved in 2 steps.

Summary of the solution

Heres a summary of the solution:

First, you split the 8 pennies into 3 groups of pennies 2 groups with 3 pennies each and 1
group with 2 pennies. Then, you compare the weight of the first two groups of 3 pennies each
by putting them on the scale.

Scenario #1: The 2 groups weigh the same. This means the lightest coin is in the group of 2.
So, take those 2 pennies and compare them to each other and find the lightest coin.

Scenario #2: The 1st group weighs more than the 2nd group. Take group #2 (3
pennies) and pick any 2 pennies out of that group of 3. If they weight the same, then
the third penny is lighter. If they dont weigh the same then the lighter one is obviously
the lightest penny.

1. How would you weigh an elephant without using a scale?

A: If we are not allowed to use a scale then what are our options? Well, there arent very
many.

It helps to think of natural things of which we already know the properties of. Lets think of
water thats something natural that has a lot of measurable properties.

2. What could we do with water?

A: Well, we do know that one of the properties of water is that it weighs 1 kg. per liter, or 8.34
lbs per gallon. How can we use this knowledge to our advantage to solve this problem?

3. Put the elephant in a tank

A: What if we put the elephant on a big raft inside a full tank of water?

What we could do then is measure the volume of water thats displaced and that would give
us a great approximation of the weight of the elephant.

So, say that 7500 liters (or about 1,900 gallons) of water is displaced, then that
means the elephant weighs about 7500 kilograms, or 16,500 pounds.

1. Suppose you have a 3 liter jug and a 5 liter jug (this could also be in gallons). The
jugs have no measurement lines on them either. How could you measure exactly 4
liter using only those jugs and as much extra water as you need?

A: This question was actually asked in a popular movie Die Hard With A Vengeance.

Try figuring this one out on your own before reading the answer. It should be clear that the
goal is to end up with 4 liter in the 5 liter jug, since
7 having 4 liters in the 3 liter jug is
impossible.

The answer, broken down in steps:

Step 1 : First, fill the 5 liter jug and then pour it into the 3 liter jug. The 5 liter jug now has only
2 liters left.

Step 2 : Next, empty out the 3 liter jug. Then, pour the 2 liters from the 5 liter jug to the 3 liter
jug. So, now the 3 liter jug has 2 liters.

Step 3 : Fill the 5 liter jug again, and pour 1 liter into the 3 liter jug. Now, whats left in the 5
liter jug? Well, exactly 4 liters! Theres your answer.

1. Lets say that you have 25 horses, and you want to pick the fastest 3 horses out of
those 25. In each race, only 5 horses can run at the same time. What is the minimum
number of races required to find the 3 fastest horses without using a stopwatch?

A: This question is an interesting one. Lets start by asking ourselves, what are our
limitations? Well, we dont have a stopwatch so we cant time the horses. That means that
we cant compare the race times of each horse otherwise we could simply have 5 races of 5
horse each and pick out the 3 fastest times to get the 3 fastest horses. Remember that we
can only race 5 horses in each race (otherwise we could just have one race with 25 horses,
pick the 3 fastest, and we would be done!).

Draw out a table

Quick Links

In problems like this, it helps tremendously to create some sort of visual aid that you can
refer to. With that in mind, we have created this table where each entry represents a different
horse.

View
Transcripts
Testimonials X1 X2 X3 X4 X5
View blogs X6 X7 X8 X9 X10
Top Scorers
X11 X12 X13 X14 X15
X16 X17 X18 X19 X20
X21 X22 X23 X24 X25

Lets say that we have 5 races of 5 horses each, so each row in the table above represents a
race. So, X1 X2 X3 X4 X5 represents a race, and X6 X7 X8 X9 X10 represents another
race, etc. In each row, the fastest horses are listed in descending order, from the fastest
(extreme left) to the slowest (extreme right). The fastest horses in each race are the ones on
the left so in the first race X1 was the fastest and X5 was the slowest. In the second race
X6 was the fastest, X7 was the second fastest and so on.

Only 5 horses each race

So, now we ask ourselves: what do we know after these 5 races? Well, we do have the 5 five
fastest horses from each race (X1, X6, X11, X16, and X21). But, does that mean we have the
5 fastest horses? Think about that for a second. Well, actually it does not mean that we have
the 5 fastest horses. Because, what if the 5 fastest horses just happened to be in the first
race so X1 X2 X3 X4 X5 are the fastest horses. X1, X6, X11, X16, and X21 are all the fastest
horses in their individual groups, but there could be one group that just happened to have all
of the fastest horses. Remember we havent compared all the horses to each other since we
can only run 5 horses in a race, so that is still a possibility. This is very important to
understand in this problem.

2. Work through a process of elimination

A: Well, now that weve had 5 different races, we can eliminate the slowest 2 horses in each
group since those horses are definitely not in the top 3. This would leave these horses:

X1 X2 X3
X6 X7 X8
X11 X12 X13

X16 X17 X18


X21 X22 X23

We also know the 5 fastest horses from each group but its important to remember that the
5 group leaders are not necessarily the 5 fastest horses. So what can we do with that
information?

Well, we can race those 5 horses against each other (X1, X6, X11, X16, and X21) and that
would be the 6th race. Lets say that the 3 fastest in that group are X1, X6, and X11
automatically we can eliminate X16 and X21 since those 2 are definitely not in the top 3.

What other horses can we eliminate after this 6th race? Well, we can automatically eliminate
all the horses that X16 and X21 competed against in the preliminary races since X16 and
X21 are not in the top 3 then we also know that any horse thats slower than those 2 is
definitely not in the top 3 either. This means we can eliminate X17 X18 X22 and X23 along
with X16 and X21.

Now, we also know that X1 is the fastest horse in the group since he was the fastest

horse out of the 5 group leaders. So, we dont need to race X1 anymore. Are there
any other horses that we can eliminate from further races? Well, actually there are.
Think about it if X6 and X11 are the 2nd and 3rd fastest in the group leaders, then
we should be able to eliminate X8 since X6 raced against him and he was in 3rd place
in that race. X7 could only possibly be the 3rd fastest, and since X8 is slower than X7,
we can safely eliminate X8. We can also eliminate X12 and X13 since X11 was the 3rd
fastest in the group leaders, and X12 and X13 were slower than X11.

So, all together we can eliminate these horses after the 6th race: X17 X18 X22 X23 X16 X21,
X12, X13, X8 and X1. This leaves us with the following horses to determine the 2nd and 3rd
fastest horses:

X2 X3
X6 X7
X11

3. What is the solution?

A: This means we only have 5 horses left! Now we race those horses one more time in the
seventh (7th) race and we can take out the top 2 horses and that would mean we have the
2nd and 3rd place horses! So, we have found our answer! It takes 7 races to find the top 3
horses in this problem.

1. Theres an activity in America, with one-on-one contests, and a national


championship. The same person won the championship on two different occasions
about 65 years apart. Name the activity.

A: This was a question that Charlie Munger (a partner of Warren Buffets) asked a group of
students in a speech he gave. This is a fun question to try to answer, because it really is just
a test to see your analytical skills. Try to figure this out on your own were sure that you
can figure out the answer on your own if you think carefully.

Breaking the problem down

Lets figure this out. Well, since the championship was won by the same person over a span
of 65 years, that means the second time around this person must have won the
championship when he was at least 85 years old, and thats assuming that he first won the
championship when he was at least 20 years old.

This also means that theres no way that this activity requires any hand eye coordination
because anyone over 85 years old will simply not be able to beat someone in his 20s. So,
theres no way this was a billiards tournament, and definitely not a tennis tournament.

What about a chess tournament? Well, even though it is a mental game, it does require quite
a bit of stamina and is far too competitive for an 85 year old to be competitive at a national
level, even if he can beat a lot of other younger people. If not chess, then what about
checkers? Well, that sounds like a potential answer! Because, that is definitely a game
where experience can make you the best even though you may be 85 years old. And its also
a game which does not require much stamina, or any athleticism at all. And that is the
correct answer it is a checkers tournament.

The name of this person, in case you were wondering is Asa A. Long (born on 20 Aug 1904).
He became
the youngest US national champion, at 18 years old 64 days, when he won in Boston,
Massachusetts, USA on 23 Oct 1922. He then became the oldest person to win the national
checkers tournament in America, at age 79 years 334 days

when he won his sixth title in Tupelo, Mississippi, USA on 21 Jul 1984.

1. Four people need to cross a rickety rope bridge to get back to their camp at night.
Unfortunately, they only have one flashlight and it only has enough light left for
seventeen minutes. The bridge is too dangerous to cross without a flashlight, and its
only strong enough to support two people at any given time.

Each of the campers walks at a different speed. One can cross the bridge in 1
minute, another in 2 minutes, the third in 5 minutes, and the slowest camper takes 10
minutes to cross. How can the campers make it across in exactly 17 minutes?

A: Lets start out trying to solve this problem by re-stating some of the facts that we have:
only 2 travelers can cross the bridge at a time, there is only one flashlight, each traveler has a
different speed, and our goal is to have all travelers cross the bridge in exactly 17 minutes. It
always helps to restate the relevant facts so that we can narrow down the parameters of the
problem.

So, its clear that there will need to be someone who brings back the flashlight every time.
This means that it makes the most sense to have 2 people cross the bridge at a time, but
only have one person bring back the flashlight. And, why not just have the fastest person
bring back the flashlight every time the 1 minute person? Heres what it would look like if
each line represents a separate trip, and if we just use their time in numbers to refer to the
campers:

Trip

Elapsed Time

5 10 ------------- 2 1 ------------------->

5 10 <------------1 ------------------- 2

10 ---------------5 1 ------------------- >2

10 <------------- 1 --------------------- 5 2

------------- 10 1 -------------------->

10

Total Elapsed time: 19 minutes

We were only able to get all of the campers over the bridge in 19 minutes. But, the question
clearly asks us how to do it in 17 minutes. How can we improve? Well, lets ask ourselves
this question: what assumptions did we make that we can improve on? We did assume that
having the 1 minute camper come back every time is the best way to do this. That sounds
like there may be some room for improving that assumption, and, in fact, there is: it seems
like having 10 and 1 cross the bridge at the same time is a waste, because anyone who
crosses the bridge with 10 will have to take 10 minutes since 10 will slow them down. Why
not have instead have 10 go with the second slowest camper, 5, and then have 2 come back?
So, it would look like this:

Trip

Elapsed Time

5 10 ------------- 2 1 ------------------->

5 10 <------------- 1 ------------------- 2

1 ------------- 5 10 ------------------- >2

1 <------------- 2 --------------------- 5 10

------------- 2 1 ------------------>5 10

10

Total Elapsed time: 17 minutes

And, voila! We have our answer as shown above!

1. Suppose you have 8 marbles and a two-pan balance used to compare the weight
of 2 things. All of the marbles weigh the same except for one, which is heavier than
all of the others. How would you find the heaviest marble if you are only allowed to
weigh the marbles 2 times?

A: Lets start solving this puzzle by keeping it simple. What if we just divide the 8 marbles
into 2 groups of 4 each, and we put 4 marbles on one pan and 4 marbles on the other. What
do we know after the first weighing? Well, we know which group of 4 marbles is heavier, which
means that we also know that the heaviest marble is in that group.

Now, weve narrowed it down to 4 marbles, and we know one of those marbles is the heaviest
and this is after one weighing. Can we find out the heaviest marble in one more weighing
with just 4 remaining marbles? What if we just compared 2 marbles one marble on each
pan? Well, if one of those happened to be the heavier marble then we would know which
marble is the heaviest in 2 weighings. But, one of those 2 marbles is not necessarily the
heavier one and we dont know which of the other 2 marbles that were not weighed is
heavier. So that is an assumption that we can not safely make, and our solution is not valid.

What if we just put 2 marbles on each pan and do another weighing? Well, one side would be
heavier, and we would be able to narrow it down to 2 marbles but we still dont know which
of those 2 marbles is heavier. This would require one more weighing, for a total of 3 when
the question specifically asks us to find the heaviest marble in just 2 weighings. This means
that our solution so far has been invalid, and we must come up with a new and better
solution.

Challenge our assumptions

We started with the assumption that we should put all the marbles on the scale. What if we
left some off of the scale? Could that possibly tell us something? Well, yes, it actually does
tell us something by the process of elimination. Because, if we know that the marbles on the
scale weigh the same, then we also know that the heaviest marble is one of the marbles not
on the scale (so we can eliminate the marbles on the scale). And if the marbles on the scale
do not weigh the same, then we know that one of the marbles on the scale is the heaviest,
and we can eliminate the marbles that are not on the scale.

So, lets do this: we put 3 marbles on each pan for a total of 6 marbles on the pan, and we
leave 2 marbles off the pan. Then, we compare the 6 marbles on the pan if one side is
heavier than the other then we only have 3 marbles left. We can compare 2 of those 3
marbles to each other, and if they are the same weight then the 3rd is the heaviest, and if one
is heavier than the other then we have the heaviest in just 2 weighings. If, when comparing the
6 marbles we find that both sides are equal, then we know that the heaviest marble has to be
in the 2 marbles that are not on the pan. This then means that we only have to compare
those 2 remaining marbles and we have the heaviest marble. So, we have found our answer!

1. Given the previous puzzle (click here to read it), with 8 marbles, how would you
generalize the solution to find the minimum number of weighings if you are given n
marbles?

A: You should take a look at the previous riddle in order to understand this question better.
Now the interviewer wants to see whether you just got lucky and stumbled on an answer in
solving the previous riddle, or if you actually understood the problem.

Whats the best way to start generalizing our solution so that it works even for n marbles?
Well, lets try to break down the solution we found when we had exactly 8 marbles and we
only had to do 2 weghings to find the heaviest marble. What exactly happened after each
weighing? Well, after each weighing we were able to eliminate 2/3 of the marbles, but we kept
1/3 of the marbles for the next weighing.

Is there a way we can take this information and generalize it into a solution for n marbles?
What if we started out with 9 marbles? Well, we could find the heaviest marble with just 2
weighings as well because in the first weighing we could eliminate 2/3 or 6 of the marbles,
and in the second weighing we could eliminate 2/3 of the remaining 3 marbles or 2 marbles,
which would leave us with just the heaviest marble. It sounds like with every weighing we
would be left with 1/3 of the marbles, and once we get to just one marble, then we are done
since we have found the heaviest marble.

Come up with an equation

Another way of saying this is that, if x is the number of weighings and n is the number of
marbles, then 3x would equal n. This is true in the scenario where we have 9 marbles,
because 32 is equal to 9 so it takes 2 weighings to find the heavy marble out of 9 marbles.
So, if x is the minimum number of weighings to find the heavy marble, then this would mean
that x = log3n.

What if we just had 8 marbles would that equation (x = log3n) still apply? Actually, it would
not because of the fact that the the log38 is equal to 1.893 and we can not have 1.893
weighings we can only have whole numbers. So, what needs to be done here? Well, we
would need to round up to 2. But, the real question is whether rounding up would be valid for
all other number of marbles.

2. Does rounding up always work?

A: Lets see if rounding up works for 10 marbles. log310 would give us a little more than 2
so if we round up to 3 would that be valid? In other words, in only 3 weighings can we find the
heavy marble out of 10 marbles? Lets break it down we would start out with 2 groups of 3
(which we put on the scale) and one group of 4. Then, after one weighing we would be left with
either 3 marbles or 4 marbles, depending on which group the heavy marble is in. If its in the
group of 3 marbles we would need one more weighing to find the heavy marble, for a total of 2
weighings. However, if the heavy marble is in the group of 4, then we would need 2 more
weighings for a total of 3 weighings. So, the answer varies depending on where the marble is.
But, the question asks us to find the minimum number of weighings in which we are
guaranteed to find the heavy marble, and that would be 3 weighings in this case.

So, we would have to round up in every case we have a fractional number in order to find the
heaviest marble, and another way of saying that is we want to find the ceiling of log3n. And
that is the correct answer given n marbles, it takes ceiling (log3n) weighings to find the
heavy marble.

One interesting thing to note here is how much easier it would have been to solve the

previous problem if the number of marbles was 9, because you are able to split the
marbles into 3 groups of 3. But, with 8 marbles, the problem becomes more difficult
and forces you to think a bit more. So, its always good to remember to try out
different scenarios, and not to be misled into thinking about the problem in the wrong
way because of a small detail in the problem.

1. You have 2 fuses and a lighter. When each fuse is lit, it takes exactly one hour to
burn from one end to the other. You can not make any other assumptions about the
fuses they are not identical, they do not burn at a constant rate, and their length

has nothing to do with the time remaining (so just because half of the fuse is left
does not mean that half an hour is left before the fuse is finished).

Using only those 2 fuses and the lighter, how would you measure a period of exactly
45 minutes?

A: When you first think about this puzzle (it may even be called a riddle), it may seem
impossible to find a solution. But, there must be an answer since someone is asking this
question. What do we have and what do we know? We have 2 fuses, a lighter, and we know
each fuse takes one hour to burn. It seems like all we can do is measure one hour, since we
cant make any other assumptions. So, this means we must really try to think creatively,
because there is something here that we are missing.

Thinking outside the box

What if we start the flame from the middle of a fuse? Would that allow us to measure half an
hour? Actually, no it would not, because we can not assume that half of the length of the fuse
would burn in half an hour it may just be that 1/10th of the length of the fuse take 50
minutes to burn and the other 9/10ths of the fuse takes 10 minutes to burn. So, starting the
flame in the middle of the fuse is not a valid option.

What would happen if we burn a fuse from both sides? That sounds interesting. Well, what

would happen is that the fuse would burn out in just 30 minutes this is because the fuse
would be burning from both sides and the flames would burn until they meet each other and
extinguish after exactly 30 minutes. Well, that sounds very useful because we can now
measure 30 minutes!

Now that we can measure 30 minutes, how could we measure 15 minutes more to get
45 minutes total? Well, can we use the idea of burning a fuse from both sides to
measure that extra 15 minutes? That sounds like it has potential what if we burn
fuse # 1 from both ends, and we burn fuse #2 from only one end. Then, after 30
minutes has passed, we can burn the other end of fuse #2. Fuse #2 would finish
burning in 15 minutes because it has already has 30 minutes worth of time burned
from it, but it is also burning from both ends so that cuts the burning time in half.
And 30 + 15 would give us 45 minutes so we finally have an answer!

1. Suppose 2 boys are walking in the woods and they decide to take a shortcut
through a railroad tunnel. They had walked 2/3 of the way through the tunnel, but
then something horrible happened: a train was coming in the opposite direction, and
it was coming close to the entrance of the tunnel. Each boy ran in a different
direction to get out of the tunnel and avoid the incoming train. Each boy ran at the
same exact speed of 10 miles per hour, and each boy managed to escape the train
at the exact instant in which the train would have hit and killed him. If the train was
moving at a constant speed and each boy was capable of instantaneous
acceleration, then how fast was the train going?

A: Take a look at the diagram below to visualize the problem. Let A and B be the 2 boys, and

you can see that they are both running in opposite directions. You can see that they boys
had walked 2/3 of the way through the tunnel, and you can also see the train approaching.

<--------------- 2/3 --------->|<--- 1/3 ----->|

<- B A ->

<----TRAIN

----------------------------------------------At first this may seem like an algebra problem, but as soon as you start using your variables
(the x and y's) you will notice that it is not really an algebra problem that deals with rates and
the boys' speeds - because you are missing important information like distances and times.
Clearly, this problem requires something other than algebra.

Review the relevant information

So, what other information is important here? The fact that the boys barely escape sounds
pretty important and relevant to solving the problem. It's also important to note that each boy
would have been hit by the train at a different time - since they were running in different
directions. This means that B would have been hit by the train at a later time than A since A
was running towards the train whereas B was running away from the train.

This means that A barely escapes by the time the train comes right into the tunnel. But,
where is B when the train is right about to enter the tunnel? Because A had to pass 1/3 of the
tunnel to get out, and because B runs at the same exact rate as A, it must mean that B has
also passed another 1/3 of the tunnel by the time the train is right outside the tunnel. Which
means that B has to pass another 1/3 of the tunnel in order to get out. This is what a drawing
of this would look like:

<-----1/3---------->-------------------------

<- B

<-TRAIN

---------------------------------------------- A

Remember that B will get out of the tunnel at the exact moment when the train was about to
hit him. This means that the train will travel the entire length of the tunnel, and B will travel
just 1/3 of the tunnel - but they both get to the end of the tunnel at the same time. This also
means that the train must travel 3 times as fast as B (since B only travels 1/3 of the tunnel in
the same time as the train). And since B travels at a speed of 10 miles per hour, the train
moves at 30 miles per hour (3 * 10). So, we have our answer!

< Prev

You might also like