Balls question

For everything that's not in any way related to PureBasic. General chat etc...
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Shake the bag...

If the ball is light it will sink to the bottom.... if it's heavy it will surface above others...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

netmaestro wrote:Alas, the only prize on offer is "Biggest Cheapskate", which is yours (if you want it!) Again, good work.
Humbug!

Right, xmas is cancelled this year! :D
I may look like a mule, but I'm not a complete ass.
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post by Jan Vooijs »

my 2 cents in just 5 minutes thinking, no paper used no computer, no internet aka NO google.

12 balls, divide in two sets of 6 balls (both sets on the scale = 1$). The one who goes UP has the ligthweight ball (1 of 6 balls).

next devide the 6 balls in two sets of 3 balls (both sets on the scale = 1$). The one set (of three balls) who goes UP has the ligthweight ball (1 of 3).

now we have 3 balls (oops odd).

next divide in three sets of ONE ball. Any two balls on the scale.

a) if even (balanced) the other ball NOT on the scale is the lightweight.

b) the one who goes UP is the leightweight ball

Total 3 times usage of the scale, so 3 bucks.

No messy fiddling with all kinds of colored balls or usage of calculators (joke)....
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

That's pretty expensive as one complete use of the scales is wasted.

Here is some pseudocode I had kicking around:

Code: Select all

MARKINGS: U = UNCLASSIFIED
          G = GOOD
          H = POSSIBLY HEAVY
          L = POSSIBLY LIGHT

MARK ALL BALLS 'U' 
WEIGH 4U VS 4U LEAVING 4U
IF BALANCE
   REMARK 8 BALLS 'G' 
   WEIGH 3U,1G VS 4G
   IF BALANCE
      REMARK 3 BALLS G
      WEIGH IG VS 1U -> DONE
   ELSE
      IF 3U,1G ^
         REMARK 3U 'L' 
         WEIGH 1L VS 1L LEAVING 1L -> DONE
      ELSE
         REMARK 3U 'H' 
         WEIGH 1H VS 1H LEAVING 1H -> DONE
      ENDIF
   ENDIF
ELSE
   REMARK 4 BALLS 'G'
   REMARK 4 BALLS 'H'
   REMARK 4 BALLS 'L'
   WEIGH 2H,2L VS 1H,3G LEAVING 1H,2L
   IF BALANCE
      REMARK 3H,2L 'G'
      WEIGH 1L VS 1L LEAVING 1H -> DONE
   ELSE
      REMARK 1H,2L 'G'
      IF 2H,2L ^
         REMARK 2H 'G'
         WEIGH 1L VS 1L LEAVING 1H -> DONE
      ELSE
         REMARK 2L,1H 'G'
         WEIGH 1H VS 1H LEAVING 1L -> DONE
      ENDIF
   ENDIF
ENDIF
 
Last edited by netmaestro on Wed Feb 22, 2006 5:22 am, edited 5 times in total.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Jan Vooijs wrote:my 2 cents in just 5 minutes thinking, no paper used no computer, no internet aka NO google.
12 balls, divide in two sets of 6 balls (both sets on the scale = 1$). The one who goes UP has the ligthweight ball (1 of 6 balls).
As netmaestro pointed out, we are not told whether the odd one out is underweight or overweight, and as such, comparing 6 balls with 6 is a wasted use of the scales as all that tells you is that one of the balls does not weight the same as the remaining 11 !

Incidentally, what exactly would someone type into google anyhow? I shudder to think what would turn up (apart from the police) if I typed in 'balls' !

Try 5 cents next time!
I may look like a mule, but I'm not a complete ass.
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Re: Balls question

Post by Jan Vooijs »

@NetMeastro,
Ooh crap you are right!! I presumed a lightweight ball!! My bad.

But that corrects itself after my second set of (light) balls they are equal so i know to look for a heavy ball in the other set of 6 balls. So 3 and 3 balls and three 1 balls if they are equal the heavy ball is the remaining one ball. Same principle. But yes 3 or 4 uses of the scale no more.

There is a error in your own code after the else statement of the second weighing.
you code:

Code: Select all

      ELSE
         REMARK 2L,1H 'G'
         WEIGH 1H VS 1H LEAVING 1L -> DONE
      ENDIF 
the "LEAVING 1L" is wrong. There is NO 1L the "REMARK 2L,1H 'G'" got the 2 only L you have left, you only have the 2H to weigh to know which of both is the heavy one!!

So this is the correct code:

Code: Select all

      ELSE
         REMARK 2L, 1H 'G'
         WEIGH 1H VS 1H -> DONE
      ENDIF 
You say the answer that Srod gives is correct but it USES allways 4 times to weigh??? Where he states "2nd comparison tells us whether one of ABC" is the 3rd time he is using the scale not the 2nd!! Than he continues to wheigh balls A&B makes it four times!!

-------------------
@Srod,
Looking on google for "balls problem" see the top two entries??? That was what I meant by looking on the internet aka google (and NO dirty pictures).[/code]
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I should point out that in those days I wrote mainly in COBOL...

@srod: The cleverest problem solvers get a handle on it in under 15 minutes, and prove it in under an hour. You certainly fit into that group. Good work.
Last edited by netmaestro on Wed Feb 22, 2006 5:24 am, edited 2 times in total.
BERESHEIT
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I should point out that in those days I wrote mainly in COBOL


Every have a competition to see who could get the most errors from a single PIC ?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You say the answer that Srod gives is correct but it USES allways 4 times to weigh??? Where he states "2nd comparison tells us whether one of ABC" is the 3rd time he is using the scale not the 2nd!! Than he continues to wheigh balls A&B makes it four times!!
You don't actually use the scales again, I'm simply referring back to the second comparison which provides quite a bit of info. I really don't think you've read this solution in full.
I may look like a mule, but I'm not a complete ass.
Post Reply