Archive for June, 2007

Pirates !


Five pirates have 100 gold coins.They have to divide up the
loot.In order of seniority,each pirate proposes a distribution
of the loot.All the pirates vote,and if at least half accept the
proposal,the loot is divided as proposed.If not,the most senior
pirate is eliminated,and they start over again with the next
senior pirate.What solution does the most senior pirate
propose? Assume they are very intelligent,extremely greedy,
and interested in surviving.

09.png

Solution:

The most senior pirate knows that he needs to get two other pirates
to vote for his solution in order for him not to be eliminated. So why
would any pirate vote for him? The next most senior pirate would
surely see it in his self-interest for the senior pirate to be eliminated.
Letís start simplifying. If there were only one pirate, there would
be no puzzle. The pirate would take all the loot, and no one
would complain.
Now consider the situation with two pirates. Same outcome. The
senior pirate takes all the loot, and the other pirate can’t do a thing
about it as the senior pirate’s vote represents half of the voters.
It gets more complicated for the senior pirate when there are
three pirates. Let’s number the pirates from least to most senior:
1, 2, and 3. With three pirates, pirate 3 has to convince at least one
other pirate to join his collation. Pirate 3 realizes that if his plan
is not adopted, he will be eliminated, and they will be left with two
pirates. All of them know what happens when there are two pirates:
pirate 2 takes all the loot himself and pirate 1 gets nothing. So pirate
3 proposes that he will take 99 gold coins and give 1 coin to pirate
1. If pirate 1 has any self-interest at all, he really has no choice. If
pirate 1 rejects the offer, he gets nothing. So pirate 3ís plan will
pass two to one over pirate 2ís objection.
With four pirates, an even number, the senior pirate needs just one
vote other than his own to impose his will. His question now is which
one of the other pirate’s votes can be exchanged for the fewest number
of coins. Pirate 2 recognizes that he is most vulnerable. Therefore, pirate
4 knows that if he gives pirate 2 anything at all, he will vote for it.
A rule is emerging here. In each case, the senor pirate should buy
only the votes he needs, and buy them as cheaply as possible. Apply
the rule to the five-pirate case. Pirate 5 needs two votes plus his own.
The goal is to toss a coin or two to pirate 1 and pirate 3, the two
pirates in the most vulnerable positions. Both will be empty-handed .

if the senior pirate is eliminated and four pirates remain. So pirate
5 offers one coin to pirate 3 and one coin to pirate 1. Pirates 2 and
4 get nothing.

Click here for detailed solution.

Leave a comment

Why nine minutes?


Many consumer alarm clocks have a snooze button that is
calibrated for 9 minutes.Does that sound like an odd
decision? Many people would think a 10-minute snooze
interval would make more sense.So were the designers asleep?
Why 9 minutes?

991126.gif

By setting the snooze time to 9 minutes, the alarm clock only needs to
watch the last digit of the time. Whether implemented by physical circuitry
or software, it is easier to manipulate just the terminal digit.

Leave a comment

putchar to int!


Print an integer using only putchar. Try doing it without using extra storage.

void print_to_int(int x)
{
if(x <=9)
{putchar(x+'0');
return;
}
else
print_to_int(x/10);putchar(x%10+'0');
}

Leave a comment

Level order traversal!


For the level order of the binary tree:

1- start from the root, display it

2-put the left child and then right child in a queue

3-again consider the first element of the queue as root and repeat the procedure till the whole tree is traversed.

here is the C code :

void levelorder(struct tnode *p)
{
struct tnode *queue[100]={(struct tnode*) 0};
int size=0;
int qptr=0;
while(p)
{
printf("%d\t",p->data);
if(p->left)
{
queue[size++]=p->left;
}
if(p->right)
{
queue[size++]=p->right;
}
p=queue[qptr++];
}
}

Leave a comment

Linux and Women!


linuxchix_logo.gif

Have you ever thought about the absence of girls as Linux users? Have you seen any girl struggling with failed dependencies of a rpm package? Can’t they struggle? or this is just a result of their lack of interest in computation in general?

I found the point discussed here and they have pointed out few reasons for their lack of interest(with results based on few researches) .

  • Women are less confident
  • Women have fewer opportunities for friendship or mentoring
  • Women are discouraged from an early age
  • Computing perceived as non-social
  • Lack of female role models
  • Life-work balance more important to women

Do you agree? How can we promote  Linux to women ? 😉
LinuxChix is a community for Linux-women.

linuxchix.gif

Tutorials for Girls to start with

Leave a comment