Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An organisation produces packets of balls. Each packet has ten balls of five colours. Total weight of packet is expected to be 10 KGs (1 KG) each ball. But, due to some machine error every time packet manufactured is of 12 KGs i.e. two balls of same colour are 2 KGs each. [4 Colours X 2 Balls X 1 KG =8 KG, 1 colour X 2 Balls X 2 KGs = 4 KGs. Total = 12 KGs]
Note: Every packet may have different colour of defected ball.

Think of a logic/Program in any language to find out the colour of defected ball using a weighing machine in one attempt. Weighing machine has two sides X and Y and shows always shows the difference of both sides.

Colours are : Red, Green, Blue, White, Yellow.

What I have tried:

can we solve in permutation and combination.
Updated 18-Oct-20 11:36am
Rick York 18-Oct-20 15:51pm    


Well, maybe.
OriginalGriff 18-Oct-20 16:24pm    
Careful - you might get the job instead of the OP! :laugh:
Rick York 18-Oct-20 17:30pm    
Good point.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

This task is about you thinking about what to do, not us. It's a test of your ability to analyse a problem, and come up with a solution, test it, and implement it in the language of your choice.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
Each ball can go on the left tray (L), right tray (R), or no tray (x). So for the two balls of each colour, the combinations are LL, LR (=RL), RR, Lx, Rx, or xx. If you start playing around with some actual test cases, you'll probably figure out a strategy.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900