Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Christmas Brain Teaser Fun
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual ProMatrix
Divers
Thread ID:
00065780
Message ID:
00066115
Vues:
24
>You have 12 billiard balls. All but one of the billiard balls are of equal weight. The one odd bal :) is either lighter or heavier. You do not know which. You have 3 (balance) scale weighings to determine not only which ball is the odd one but also whether it is lighter or heavier. You must be able to give logic for all possibilies.
>
>Good Luck. :)

What you think about that:

note: i add a prefix, 'h' for possibly heavier
and 'l' for possibly lighter for readability.

*//////////PSEUDOCODE////////////*
*12 balls 1,2,3,4,5,6,7,8,9,10,11,12
*1st; 1,2,3,4 vs 5,6,7,8
do case
	case 1,2,3,4 heavier (9,10,11,12 are out/rest h1,h2,h3,h4,l5,l6,l7,l8)
		*  2nd; h1,h2,l5 vs (10),h3,l7 (h4,l6,l8 are left)
		do case
			case h1,h2,l5 is heavier (h3,h4,l5,l6,l8 are out/rest: h1,h2,l7)
				* 3rd h1,l7 vs (10),(11) (h2 is left)
				do case 
					case h1,l7 is heavier (h2,l7 are out)
						1 win heavy
					case (10),(11) is heavier (h1,h2 are out)
						7 win light
					case even
						2 win heavy
				endcase		
			case (10),h3,l7 is heavier (h1,h2,l7 are out/rest: h3,l5)
				* 3rd h3,l5 vs (10),(11)
				do case 
					case h3,l5 is heavier (l5 is out)
						3 win heavy
					case (10),(11) is heavier (h3 is out)
						5 win light
				endcase		
			case even (h1,h2,h3,l5,l7 are out/rest: h4,l6,l8)
				* 3rd h4,l6 vs (11),(12)
				DO CASE
					case h4,l6 are heavier (l6,l8 out)
						4 win heavy
					case (11),(12) are heavier (h4,l8 are out)
						6 win light
					case even
						8 win light
				endcase			
		endcase	

	case 5,6,7,8 heavier (9,10,11,12 are out/rest l1,l2,l3,l4,h5,h6,h7,h8)
		*  2nd; h5,h6,l1 vs (10),h3,l3 (h8,l2,l4 are left)
		do case
			case h5,h6,l5 is heavier (h7,h8,l1,l2,l4 are out/rest: h5,h6,l3)
				* 3rd h5,l3 vs (10),(11) (h6 is left)
				do case 
					case h5,l3 is heavier (h6,l3 are out)
						5 win heavy
					case (10),(11) is heavier (h1,h6 are out)
						3 win light
					case even
						6 win heavy
				endcase		
			case (10),h3,l3 is heavier (h5,h6,l3 are out/rest: h7,l1)
				* 3rd h3,l1 vs (10),(11)
				do case 
					case h7,l1 is heavier (l1 is out)
						7 win heavy
					case (10),(11) is heavier (h7 is out)
						1 win light
				endcase		
			case even (h5,h6,h7,l1,l3 are out/rest: h8,l2,l4)
				* 3rd h8,l2 vs (11),(12)
				DO CASE
					case h8,l2 are heavier (l2,l4 out)
						8 win heavy
					case (11),(12) are heavier (h8,l4 are out)
						2 win light
					case even
						4 win light
				endcase			
		endcase	

		
	case even
	* 2nd; (1),10 vs 11,12  (9 is left)
		do case
			case (1),10 is heavier
				* 3rd (1),(2) vs 10,11 (12 is left)
				do case	
					case (1),(2) is heavier 
						11 win lighter
					case (1),(2) is lighter
						10 win heavy
					case even
						12 win light
				endcase	
			case 11,12 is heavier
				* 3rd (1),(2) vs 10,11 (12 is left)
				do case	
					case (1),(2) is heavier 
						10 win light
					case 10,11 is heavier
						11 win heavy
					case even
						12 win heavy
				endcase
			case even
				(9 win)
				* 3rd 9 vs (1)
				to determine if 9 is heavy or light
		endcase
endif
*/////////////////////////*

Cool!

:0)
If we exchange an apple, we both get an apple.
But if we exchange an idea, we both get 2 ideas, cool...


Gérald Santerre
Independant programmer - internet or intranet stuff - always looking for contracts big or small :)
http://www.siteintranet.qc.ca
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform