Created
September 20, 2021 15:06
-
-
Save dwaard/aab290e4e7f4c6aab857e74d0358e880 to your computer and use it in GitHub Desktop.
Pseudo code solution for the 9 ball problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Divide balls a - i into THREE groups. | |
// Use two of them to weigh on the scales, ignore the third | |
if (abc < ghi) { | |
// a, b or c must be lighter | |
// Take any two of these to compare, ignore the third | |
if ( a < c ) { | |
console.log("a is lighter"); | |
} else if ( a == c ) { | |
console.log("b is lighter"); | |
} else { | |
console.log("c is lighter"); | |
} | |
} else if (abc == ghi) { | |
// d, e or f must be lighter | |
// Take any two of these to compare, ignore the third | |
if ( d < f ) { | |
console.log("d is lighter"); | |
} else if ( a == c ) { | |
console.log("e is lighter"); | |
} else { | |
console.log("f is lighter"); | |
} | |
} else { | |
// g, h or i must be lighter | |
// Take any two of these to compare, ignore the third | |
if ( g < i ) { | |
console.log("g is lighter"); | |
} else if ( a == c ) { | |
console.log("h is lighter"); | |
} else { | |
console.log("i is lighter"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment