Tangler Discussion Forums

Discuss

Topics

Click a Topicto start discussing

    ok chums, these are google interview questions... so I don't have the answers. can't wait to hear yours though

    2009-11-14 12:08:00.0

    1.

    You're the captain of a pirate ship and your crew gets to vote on how the gold is divided up. If fewer than half of the pirates agree with you, you die. How do you recommend apportioning the gold in such a way that you get a good share of the booty, but still survive?

    2009-11-14 12:08:06.0

    2. You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?

    2009-11-14 12:08:30.0

    3.You have eight balls all of the same size 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?

    2009-11-14 12:10:02.0

    4. You are given 2 eggs You have access to a 100-story building. Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100th floor. Both eggs are identical. You need to figure out the highest floor of a 100-story building an egg can be dropped without breaking. The question is how many drops you need to make. You are allowed to break 2 eggs in the process

    2009-11-14 12:13:37.0

    1. Is an old riddle, easily googled (ironically)

    Pretty sure we've seen 4, or a variant thereof before

    3. is old, very sure we've seen that and probably harder versions before.

    2. is interesting though.

    2009-11-14 15:26:37.0

    1. Is actually missing part of the riddle... the bit where it says what happens if you die. The canonical riddle says that in that case, the next most senior pirate suggests a different allocation of gold (and again, if voted against will be killed).

    So the base case is where you have 2 pirates, call them A and B, with B having seniority. B can give himself all the gold, vote for his own suggestion and over-rule A (because to be killed you have to have less than half the group on your side).

    Add a 3rd pirate, C, senior to the other 2. If he suggests giving himself all the gold, B will vote against because he can get all of the gold if C is killed. Assuming pirates are spiteful A will also vote against, because he's no better off than if C fails. If C suggests giving A one piece of gold (smallest possible amount, the original says there were 100 gold coins) then he'll vote in favour and C's suggestion will be passed.

    Add a 4th pirate, D. Whatever D suggests, C will vote against - he stands to gain by killing off D. B knows that if D fails, he will get nothing because C will bribe A, so B will vote in favour if given 1 piece of gold. D and B voting together have a majority (50/50 split is good enough) so that's all D needs to give away.

    Add a 5th pirate E. D will vote against, C will vote in favour if given 1 piece, B knows he'll get one piece from D anyway so he's not cheap to buy, but offer A one piece (better than he'll get if D succeeds) and he'll vote in favour.

    So in general, you need only offer 1 piece of gold to every alternate pirate under you in the hierarchy to secure support for your suggestion, because all those you offer gold to will know that it's a better offer than they'll get from the next in line, and that the next in line can secure a majority for their suggestion. All the ones you don't offer gold to aren't worth trying to win support from in the first place because they all know they'll get the same 1 piece from the next guy in line, and you don't need them for a 50/50 win.

    2009-11-14 15:39:25.0

    For 3. you take the 8 balls and put them into 2 groups of 3 and one group of 2.

    Weigh the 2 groups of 3 against each other, and they'll either be unbalanced (group 1 heavier or group 2 heavier) or balanced.

    If they balance, the odd-ball is in the group of 2, so the second weighing is those 2 balls against each other to find the heavier one.

    If they don't balance, you take the heavier group of 3 and put one aside. Weigh the other 2 against each other - if one is heavier they won't balance and you know that's the odd-ball. If the 2 you weigh do balance then the odd-ball is the one you put aside.

    2009-11-14 15:42:42.0

    4. was solved here, the answer is 14.

    2009-11-14 16:00:34.0

    For 2. you write your public key on the card. Write on the card "hey Bob, here's my public key, encrypt my phone number with it and send it back to me". Then through the magic of mathematics only someone with your private key (which should only be you) can decrypt the message and check the phone number.

    That or write your email address on the card. But that only works because it steps outside the limitation of Eve having access to all of your communications. Having an independent, secure channel to communicate on makes the encryption pointless. On the other hand this means giving Eve your email address, which might be as bad as giving her your phone number.

    2009-11-14 16:04:58.0

    Ok: here are my solutions without looking at what anyone else has posted. Though logical, my answer to 4 doesnt seem like the best solution.

     

    1. Assuming pirates are selfish and have no conscience; If N = number of pirates then give (Total Booty)/((N+1)/2) to yourself and exactly half of the remaining crew. This leaves you, plus half of the pirates, happy, and the rest of the pirates with nothing! Skulduggary!

    2. Just use a simple checksum error process. Add the individual digits of bobs phone number together and write this number on a piece of paper, accompanied by 'What do the digits in my phone number add up to, is it XX? Generally if you get a phone number wrong, you only get one number wrong, meaning this solution would never fail. If the number of incorrect numbers if >1 you have a chance of calculating the same checksum, but its still very slim.

    3. Step 1: Weigh 6 (3 on each side)
       Step 2a: If they are even then put them aside and weigh the 2 remaining to find the heavy ball.
       Step 2b: If uneven weigh 2 of the 3 balls on the heavier side, if these are even then the heavy ball is the one you didnt weigh, if these are uneven then the heavy ball is the one on the low side of the balance.

    4. Drop an egg from the 50th floor. If it breaks then drop the next one and increment the floor by 1 until the next one breaks.
       For floors greater than 50: Max number of drops = N(max floor drop value)-50 + 1
       For floors less than 50: N(max floor drop value) + 1

    2009-11-15 14:43:21.0

    ah just checked out the solution to 4. Makes sense now of course, but only really looked at it for a couple mins before I wrote up my answer

    2009-11-15 14:47:31.0

    S-K according to the information in question 2, you only need to find out if the phone number is right or wrong, so a simple error check used in all forms of data transmission like I demonstrated should suffice.

    2009-11-15 14:50:24.0

    Is your answer to 1 the same as my answer to 1? I can't tell.

    Looks like you're proposing an equal share between yourself and alternating pirates. You only need to give them a minimal amount of gold to buy their support because it's more than they'll get if you fail and the next guy gets to set the terms. If the number of discrete pieces of gold is significantly more than half the number of pirates then the captain can walk away with a large share.

    2009-11-15 19:51:18.0

    Hmm I dunno. How do you know that the next guy wont give everyone an equal share? I don't know if you can rely on future presumptions so heavily, after all you only get one shot and if it doesnt seem fair(ish) to 50% of the other pirates then off to walk the plank for you, no chance to re-evaluate!

    When I re-read the question I can spot a bit of a discrepancy, when the pirates are 'voting' is it a simple yes/no for your idea, or are they voting for several options between different suggestions from different crew members. If the latter, then my answer isn't valid.

    2009-11-15 21:13:30.0

    Your answer suggests that they have several pirates with several suggestions, which im not sure works in the riddle, judging by the fact that it is one suggestion, one vote, then when you are killed it moves to the next person's opinion, etc etc

    2009-11-15 21:15:54.0

    I was working on the basis of the stating of the problem I've seen before, where a failed vote results in the next most senior pirate becoming the captain and proposing a division of loot. It also said that pirates will prefer more deaths to fewer (hence why you have to give gold to those who would get nothing from the next guy anyway) and that they all act perfectly logically (so you can reason on their behaviour based on what they can deduce about what will happen).

    2009-11-15 21:51:58.0

    Simple restating:

    If there are 2 pirates, the more senior one keeps all the gold and there's jack all the other one can do about it because his vote doesn't beat the senior one's.

    If there are 3 pirates, the middle one in the hierarchy wants to kill the one who's turn it is to propose a plan, because then it goes to the situation where he gets all the gold. The least senior pirate gets to act as kingmaker, but will only need to be promised a small amount of gold - it's in his interests to agree, because if the vote fails it goes to the 2-pirate scenario and he gets nothing, whereas by voting in favour he gets a non-zero amount of gold.

    If there are 4 pirates, pirate 3 wants to move things along to a situation where he proposes loot division, because he can pay off pirate 1 and take most of the gold. Pirate 2 wants to avoid this scenario because he'll get nothing that way (but won't vote in favour without a little incentive). Pirate 1 is irrelevant because pirate 2 secures a majority.

    In general if there are n pirates, Pirate n proposes a division, which Pirate (n-1) will always vote against (because he wants to propose his own division), and Pirate (n-2) will want to avoid Pirate (n-1) taking control, because he knows he'll get nothing from Pirate (n-1)'s plan. That is, IF Pirate (n-1) acts logically, which we are assuming he does because it's so much harder to reason anything about people behaving illogically.

    Pirates (n-3, 5, 7 etc) know they'll get gold from Pirate (n-1)'s plan, so they'll be expensive to buy the support of, whereas Pirates (n-2, 4, 6 etc) know they'll get nothing from Pirate (n-1)'s plan, so they only need a small amount of gold promised to them to make them decide they'd rather support you than kill you.

    2009-11-15 22:01:23.0

    I agree, in the real situation onboard a pirate ship, people either wouldn't act perfectly logically, or wouldn't follow the hierarchical structure perfectly - the lowliest pirate could drum up support for a mutiny by demanding equal shares for every pirate, but that's all too messy and unpredictable for a logic puzzle, makes it more about group psychology.

    2009-11-15 22:04:39.0

    Where do you get this hierachy from? I assumed pirates votes hold equal value, with one of the pirates (the captain), deciding what they are voting on. I also take a 'vote' not in the literal sense, but in the sense that you either agree or disagree. Once the captain has explained how the loot will be divided, the "disagreers" and "agreers" will argue, fight, and eventually kill eachother. In theory the larger group wins.

    With 2 pirates (1 captain, 1 other) it doesn't work, because when they disagree they have an equal chance of losing, or (un)logically will kill eachother at exactly the same time. Nobody wins. The only answer here is to split the loot evenly between the two of you.

    With 3 pirates (1 captain, 2 others). The captain could suggest splitting the gold between himself and one other. The pirate that didn't get any would disagree, try and fight the other two and lose (death or surrender the gold). Any other arrangement would see either the captain killed, or not the maximum amount he could have taken away.

    2009-11-16 14:25:26.0

    With 4 you would need to split the gold evenly between 3 people...

    With 5 you would need to split the gold evenly between 3 people

    With 6 you would need to split the gold evenly between 4 people

     

    etc.etc

    2009-11-16 14:30:13.0

    The hierarchy came from the near identical puzzle I've seen before, that had more details. Maybe the google version deliberately omits those details so as to confuse people who have heard the question before, but I don't see how you're supposed to come up with an optimal answer without some more assumptions about how the pirates behave than the question explicitly gives you.

    2009-11-16 21:26:16.0

    hey guys - awesome answers... actually I did find the official answers online.... and you're pretty right - except for 2.  - a checksum is seen as the sub-optimal answer cos it's too complicated. the easiest answer is just tell the guy to call you. if it doesn't ring then he's got the wrong number:)

    2009-11-18 00:56:07.0

    remember, the goal was not to transfer the number, just "see if he had the right one"

    2009-11-18 01:56:34.0

    the easiest answer is just tell the guy to call you. if it doesn't ring then he's got the wrong number

    true...  *facepalm*

    2009-11-18 04:46:34.0

    You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?

     

    The first part... yeah, I guess its a good way to word it, it doesn't say you can't talk  to him....

     

    But the second part:

    Eve must return the answer to you?

    Seems kinda misleading

    2009-11-18 14:00:45.0

    so who was more right for question 1?

    2009-11-18 14:01:44.0

    Ask Bob to call you. Eve returns with the answer of whether or not he has the correct phone number (if he does, you'd know anyway since you would have spoken to him, if he doesn't Eve will return with the answer "Nope, wrong number!"). So she never needs to carry your phone number, just the answer (Yes or No!).

    2010-11-30 01:26:38.0

    it is funny with all these technologies nowadays, I would opt for following as answer for 2.

    Write on paper question ....."Bob Can you verify if you have my correct number without revealing to Eve and without talking to me in any of following methods?

    1. E-mail me at abc@xyz.com

    2. MMS me to my phone number that "If I get this MMS, then Bob has my correct number"

    3. Go to my internet website account (facebook) OR even tangler.com and write me a message for what number you have

    4. Use communicator chat software and ping me the number that you have

    5. mathematically compute like checksum or decode and send me coded number with decoding steps.   on paper back to Eve.

    2011-02-02 19:12:43.0

    did I miss any new technological tool?

    2011-02-02 19:13:02.0

    key=no-reverse give the algorithm and key to messenger . she can't find the no. unless she knows atleast single digit of no.

     

    2011-04-23 04:30:06.0

    Is this an answer to a question that wasn't asked?

    2011-04-23 06:35:11.0
To send a message, Join Now (it's quick and free) or Sign In
Edit Topic
Delete Topic
Are you sure you want to delete the topic