Skip to content

You're given 12 balls which all look the same. However, one of the balls weights differently (either lighter or heavier). Your task is to identify which ball is different and to tell whether it's heavier or lighter. The only tool you've got is a balance scale, which you can use up to 3 times. Only balls can be put on the scale cups.

Notifications You must be signed in to change notification settings

raindeer/WeighBalls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Balance puzzle

A classic job interview question goes like this:

You're given 12 balls which all look the same. 
However, one of the balls weights differently (either lighter or heavier). 
Your task is to identify which ball is different and to tell whether it's heavier or lighter. 
The only tool you've got is a balance scale, which you can use up to 3 times. 
Only balls can be put on the scale cups.

This is an implementation of a brute force solution of the above problem. It supports arbitrary number of balls and number of measurements.

Wiki entry on the problem: https://en.wikipedia.org/wiki/Balance_puzzle

About

You're given 12 balls which all look the same. However, one of the balls weights differently (either lighter or heavier). Your task is to identify which ball is different and to tell whether it's heavier or lighter. The only tool you've got is a balance scale, which you can use up to 3 times. Only balls can be put on the scale cups.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages