Friday, September 07, 2007

Indian programmers and other Asian programmers

If i got this scenario as a algorithm question:

You have two jugs, you are standing beside a well. One jug has a content of 3 ltrs and the other one has a content of 5 ltrs.

How can you get just 4 liters of water using only these two jugs?

============================================================

Indian programmers will go:

Option 1.

Solution:
1) fill the 3ltr can first and fill the same to 5ltr can. So 5ltr can has 3ltrs and 3 ltr can is empty.
2) again fill 3 ltr can and fill 5ltr for remaining 2ltrs. So 5ltr can has 5 ltrs and 3 ltr can has 1 ltr.
3) pour off/empty 5ltr can, fill the 5ltr can with the contents of 3ltr can. So 5ltr can has 1 ltr and 3ltr can is empty.
4) fill the 3ltr can and pour the same to 5ltr can. So 5ltr can has 4ltrs. the desired one:)



option 2:

Fill the 3 Ltrs Jug with water and put into 5 Ltrs jug.
Now 3 Ltrs jug is empty and there is 3 Ltrs water in 5 Ltrs Jug.
Again fill 3 Ltrs Jug with water and put into 5 Ltrs jug.
This time 1 Ltrs remain in 3 Ltrs jug and 5 Ltrs jug is full of water.
waste the water of 5 Ltrs jug, Now 5 Ltrs Jug is empty and 3 Ltrs Jug contain 1Ltr of water.
Put the 1 Ltr water of 3Ltrs jug into 5 Ltr jug which was empty.
Now 3 Ltrs jug is empty and 1 Ltr of water in 5 Ltrs jug.
Again fill the jug of 3Ltrs and put into 5 Ltrs jug(1 Ltr already in 5 Ltrs jug)
It will now become 4 litre.


and after that, they program.

================================================

Other Asian programmers:



































Get a 4litre jug and get it over with......





( we are just plain lazy.... )