File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes Glass arrangement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Glass arrangement" Watch "Glass arrangement" New topic
Author

Glass arrangement

Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870


You are looking down at nine glasses labeled 1-9. All are half filled with milk and are arranged in a 3 x 3 pattern as shown above. The following actions are performed to the glasses: Glass 4 is switched with glass 6 after glass 8 is emptied into 6. Glass 7 is emptied into glass 1. Glass 8 is moved to where glass 5 sits, while glass 5 moves to where glass 3 sits, and glass 3 is placed where 8 began. Glass 2 is emptied into glass 4. Glass 6 is emptied into glass 7, and switches places with glass 8.

Referring to the actions above, what will be the possible arrangement of the glasses
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
what is the role of the action 'emptying'? shld the glasses be arranged in the order of the quantity?
Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
"Emptied" means pouring all the content of the source glass to destination. Arrangement of galsses should be shown after swapping including their content.
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
the final arrangement:


1(full) 2(empty) 5(1/2 full)
8(empty) 6(empty) 4(full)
7(full) 3(1/2 full) 9(1/2 full)
[ October 04, 2005: Message edited by: bhuvan sundar ]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
1 2 3
4 5 6
7 8 9


You are looking down at nine glasses labeled 1-9. All are half filled with milk and are arranged in a 3 x 3 pattern as shown above.

The following actions are performed to the glasses:
Let me use following notations

E=Empty
F=Full
H=Half

Glass 4 is switched with glass 6 after glass 8 is emptied into 6.

At first,
1H 2H 3H
4H 5H 6H
7H 8H 9H

Emptying 8 into 6
1H 2H 3H
4H 5H 6F
7H 8E 9H

Switching 4 with 6
1H 2H 3H
6F 5H 4H
7H 8E 9H



Glass 7 is emptied into glass 1.
1F 2H 3H
6F 5H 4H
7E 8E 9H

Glass 8 is moved to where glass 5 sits, while glass 5 moves to where glass 3 sits, and glass 3 is placed where 8 began.
1F 2H 5H
6F 8E 4H
7E 3H 9H


Glass 2 is emptied into glass 4.
1F 2E 5H
6F 8E 4F
7E 3H 9H


Glass 6 is emptied into glass 7, and switches places with glass 8.
1F 2E 5H
6E 8E 4F
7F 3H 9H

1F 2E 5H
8E 6E 4F
7F 3H 9H

Hey its cool. Liked it very much.
----------------


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
Akhil do you work for CMM Level 5 company
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Glass arrangement