Friday, June 19, 2009
PUZZLE III: 4 women who want to cross a bridge
Woman 1: 1 minute to cross
Woman 2: 2 minutes to cross
Woman 3: 5 minutes to cross
Woman 4: 10 minutes to cross
For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes?
PUZZLE II ANSWER
The Simple C Program :
int row[]={0,1,0,1,0,0,0,1,0,1, 0,1,0,0,0,0,0,0,0,1, 0,0,0,0,1,0,0,0,0,1, 0,1,0,0,0,0,1,0,0,0, 0,0,0,0,0,1,0,0,1,1, 0,0,0,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0,1, 0,0,0,0,0,0,0,0,0,0, 0,1,0,1,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,1,1};
int Rslt[]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0};
int count=99;
int lIntNumber=0;
for(int i=99;i>0;i--)
{
lIntNumber=0;
for(int j=count;j>0;j--)
{
lIntNumber+=row[j-1]; //lIntNumber^=row[j-1];
}
if(lIntNumber%2==0)
Rslt[i]=0;
else
Rslt[i]=1;
if(i!=99)
{
int lIntPrv=0;
for(int k=i+1;k<100;k
{ lIntPrv+=Rslt[k]; //lIntPrv^=Rslt[k];
}
if(lIntPrv%2==1 && Rslt[i]==1)//OK
Rslt[i]=0;
else if(lIntPrv%2==1 && Rslt[i]==0)
Rslt[i]=1;
else if(lIntPrv%2==0 && Rslt[i]==0)//OK
Rslt[i]=0;
else if(lIntPrv%2==0 && Rslt[i]==1)
Rslt[i]=1;;
}
count--;
}
int lIntRslt=0;
for(int lIntLoop=0;lIntLoop<100;lintloop++)
{
if(Rslt[lIntLoop]==row[lIntLoop])
lIntRslt++;
}
The output most of the times comes 99.
Sunday, May 31, 2009
PUZZLES II
100 fogcreek programmers are lined up in a row by an assassin. the assassin puts red and blue hats on them. they can't see their own hats, but they can see the hats of the people in front of them. the assassin starts in the back and says "what color is your hat?" the fogcreek programmer can only answer "red" or "blue." the programmer is killed if he gives the wrong answer; then the assassin moves on to the next programmer. the programmers in front get to hear the answers of the programmers behind them, but not whether they live or die. they can consult and agree on a strategy before being lined up, but after being lined up and having the hats put on, they can't communicate in any way other than those already specified.
what strategy should they choose to maximize the number of programmers who are guaranteed to be saved?
Friday, May 29, 2009
Find Square Of a number with Simple and faster Ways
1.1 Example: Let’s find out square of 25.
Break the number to two parts with 2 as first part and 5 as second part
Find multiplication of 2 and (2+1), i.e 2 x 3 = 6
Find square of 5, i.e. 25
Hence, our answer, 252 = 6 25=625
1.2 Lets take another example, i.e. 65
65 = 6 5
6 x (6+1) = 42
Square of 5 = 25
Hence, 652 = 42 25 = 4225
1.3.Let’s take a 3 digit number, i.e. 125
125 = 12 5
12 x (12 + 1) = 156
Square of 5 = 25
Hence, 1252 = 156 25 = 15625
This way this rule can be used to calculate square of numbers ending with 5 without help of pen and paper.
Find Square of a number which is adjacent to a number that ends with 0 or 5:
We can easily find out square of a number that ends with 0 or 5, e.g. 10, 15, 20, 25, 30 etc.Now we will see how to find out square of an adjacent number like 11, 9, 16, 14, 21, 19 etc
2.1 Example: Let’s find out square of 31.
We know square of 30, i.e. 302 = 900
Now, 312 = 302 + (30 + 31) = 900 + 61 = 961
2.2 Lets find out square of 46
a. 452 = 2025
b. 462 = 452 + (45 + 46) = 2025 + 91 = 2116
2.3 Lets find out square of 71
702 =4900
712 = 702 + (70 + 71) = 4900 + 141 = 5041
Now, let’s find out numbers which are 1 less to numbers ending with 5 or 0
2.4 Find square of 14
a. 152 = 225
b. 142 = 152 – (14 + 15) =225 – 29 = 196
2.5 Find square of 29
a. 302 = 900
b. 292 = 302 – (29 + 30) = 900 – 59 = 841
Find out Square of a number near 100:
Let’s find out square numbers which are close to 100 and are lesser than 100.
3.1 Find square of 97
a. 97 is 3 less than 100 (i.e. -3)
b. 972 = 97 -3 / 032 = 94 / 09 = 9409 (There should be two digits (09 instead of 9) after ‘/’)
3.2 Find square of 96
a. 96 is 4 less than 100 (i.e. -4)
b. 962 = 96 -4 / 042 = 92 / 16 = 9216
3.2 Find square of 87
a. 87 is 13 less than 100 (i.e. -13)
b. 872 = 87 -13 / 132 = 74 / 169 =7569 (There should be two digits(69 out of 169), hence 1 is carry forwarded from 169 and added to 4 of 74)
Let’s find out square of numbers which are close to 100 and are greater than 100.
1.Find square of 103
103 is 3 greater than 100 (i.e. +3)
1032 = 103 +3 / 032 = 106/09 = 10609
2.Find square of 107
107 is 7 greater than 100 (i.e. +7)
1072 = 107 +7 / 072 = 114 / 49 = 11449
3.Find square of 113
113 is 13 greater than 100 (i.e. +13)
1132 = 113 +13 / 132 = 126 / 169 = 12769 (1 is carry forwarded from 169)
I hope this material was helpful to you.
Answer of Previous Puzzles:
PZ1:
- The state of the door depends on the number of times it will be visited as follows:if the number of times it is visited is even - the door will end up closedotherwise - the door will end up open .
- The number of times each door is visited is directly related to the number of dividers the number (door number) has (including 1 and itself).
- For example, every prime number door will be visited twice, and hence ends up closed
- So,the perfect square doors only open(including with 1)
Answer: only 1,4,9,16,25,36,49,64,81,100 will be open.
PZ2:
way1:100 th person entering will have #1 or #100 to sit..consider,crazy man(whose actual ticket no is 1) sits in #31.persons 2 to 30 occupy correct seats.now 31st person sits suppose in #32 and 32nd person may sit in #1 or even he can go for any random inbetween #33,#100..(if he chooses #1 then all others will havecorrect seats) and if he chooses any no in betwen 33,100 the successors can repeat the process and finally only either seat #1 or #100 will be empty.
so the probability is 0.5
way2:
Following this sequence, we get the following recursive relationship:
P(n) = P(n-1)(1/(101-n))
If we start to work this relationship out, we get a surprising answer:
P(1) = 1/100
P(2) = 1/99
P(3) = 1/98
and, more generally,
P(n) = 1/(101-n) ( for n<100)
so the probability is 1/2
Thursday, May 28, 2009
Puzzles I
Question 1:
100 doors in a row.You have 100 doors in a row that are all initially closed. you make 100 passes by the doors starting with the first door every time. the first time through you visit every door and toggle the door (if the door is closed, you open it, if its open, you close it). the second time you only visit every 2nd door (door #2, #4, #6). the third time, every 3rd door (door #3, #6, #9), etc, until you only visit the 100th door.
Question: what state are the doors in after the last pass? which are open which are closed?
Question 2:
Crazy Guy On The Airplane.A line of 100 airline passengers is waiting to board a plane. they each hold a ticket to one of the 100 seats on that flight. (for convenience, let's say that the nth passenger in line has a ticket for the seat number n.) Unfortunately, the first person in line is crazy, and will ignore the seat number on their ticket, picking a random seat to occupy. all of the other passengers are quite normal, and will go to their proper seat unless it is already occupied. if it is occupied, they will then find a free seat to sit in, at random.
What is the probability that the last (100th) person to board the plane will sit in their proper seat (#100)?
Please think answers will be available in the next post.