Programming Olympics / TASK: Treasure

Programming Olympics

Learn Computer Programming Here ... and maybe represent Ireland?

You are not logged in.

#1 2008-11-05 21:31:56

admin
Administrator
Registered: 2008-11-02
Posts: 56

TASK: Treasure

(a variant of this task was asked at Microsoft interviews to select candidates with exceptional logical deduction)

The pirate crew of the Jolly Roger ship have found a hoard of treasure and decide to divide it among themselves. Each pirate has a unique rank and the highest rank pirate gets to suggest how the gold should be divided. The pirates then vote on his plan. His plan is accepted if at least half the crew vote in favour of it. Otherwise, there is a mutiny and that pirate is made walk the plank. The next highest ranked pirate then takes over and the
proposal/voting procedure is repeated.

All pirates always act logically, and try to avoid walking the plank while maximising their own share of the gold.

Given that there are G gold coins in the treasure chest and P pirates in the crew, how would you suggest dividing the gold if you were the top ranked pirate?

Write a computer program to input two integers, G and P, and to output P integers, indictating the division of gold that you would suggest for the P pirates (The pirates are ordered highest to lowest, so as the highest ranked pirate, the number of
gold coins you get should be the first integer)

Examples:

(1) G=5 P=2
Answer = 5 0
You should suggest that you get all the gold. Since you would vote for your own plan, that counts as "at least half the crew", therefore it will be accepted.

(2) G=10 P=3
Answer = 9 0 1
You should suggest that you get 9 gold coins and the bottom ranked pirate gets 1. Let's number the pirates 1 to 3, 1=highest ranked, 3=lowest ranked. If your plan fails, then pirate 2 will take all the gold, so it is in the interest of pirate 3 to vote for your plan, since he gets 1 coin (otherwise he would get nothing).

Offline

 

#2 2008-11-26 15:11:18

davidmc
New member
From: Cork
Registered: 2008-11-11
Posts: 7
Website

Re: TASK: Treasure

What are the bounds???

Offline

 

#3 2008-12-01 11:35:38

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: TASK: Treasure

I've updated the task description with the following bounds:

You can assume the input will be two positive integers within these ranges:

G <= 1,000,000

P <= 1,000

(G is gold, P is pirates)

Offline

 

#4 2008-12-14 17:14:47

mc_teo
New member
Registered: 2008-12-03
Posts: 9

Re: TASK: Treasure

what should happen if the number of pirates is bigger than the amount of gold?

keep none for yourself?

Offline

 

#5 2008-12-15 11:42:53

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: TASK: Treasure

Good question.

I have updated the task description and added another constraint on the amount of Gold.

G > (0.5 x P)

This means that you can assume that the amount of Gold is strictly greater than half the number of pirates.

If there are 9 pirates, P = 9, G > 4.5.

So for P=9, you can assume there are at least 5 pieces of Gold.

Offline

 

#6 2012-01-14 10:39:57

Fodilefadu
New member
From: Teasdale
Registered: 2012-01-12
Posts: 1
Website

Re: TASK: Treasure

Hi everyone i am also new here. Looking for a great time here.


professional writer  will render any outlooks of original narrations scribed within the small time. Furnish your posers with explicit home works to them and you will get the accurate guidance trippingly. I widely access there and at-large amazed with their serves.

Offline

 

Board footer

viewtopic

Powered by PunBB
© Copyright 2002–2008 PunBB