

A swap between two adjacent balls on the outside is 'worth 4' (2 if it's our last) Order all remaining moves by this priority: x o x x oĪfter we move the 8 ball, all combinations of two adjacent swaps sharing a ball can be produced by a non adjacent swap identically, so we have to consider far less complexity at once. If you can do two adjacent swaps with it that moves two balls into position, rather than a single adjacent swap that moves just one ball into position (or a single non-adjacent if it's in a corner), do so. The next thing to do is move the 8 ball into the center. (If +0, pick +12 or randomly)įor example, this is +1 +1 +1 -1 -1 +1 -1 -1 -1 +1 +0 -1 and thus it's -1 leaning solids in corners: x o x x o This gives us a range from +12 to -12, and we aim for the extreme we are closer to. The first thing to do is calculate the parity of the exterior - +1 if it would fit 'stripes in corners', -1 if it would fit 'solids in corners', +0 if it's the 8 ball.

NOTE! This answer was written before the rotation requirement. What approach is best suited for this task that minimizes the time (in the time units described)? Would greedy be best for this? (it's how I do it when I rack them up, I guess)ĮDIT: As per existing (or previous answers) - you might assume having more stripes than solids in the corners means that strides will prefer corners - not saying it isn't true, but if you make that assumption, please prove it. Since we can use both hands, let's assume we can parallelise the first operation (swap 2 couple of balls at the same time), whereas we can only swap two non-adjacent balls at a time. To formalize this, we can assume there are two three operations we can do: If you want the white ones in the corners, you have just 2 of them in place (2,11). How do you decide that upfront? Should you take into account how many balls are already in place? In my example, if you want the grey ones in the corners, you already have 3 in place (balls 1,10,14).

There's also the decision of which types of balls we want in the corners to be made. 5 is not, we swap it with 2, then we swap 4 with 3 (or with 8), but this would already be inefficient because we've either moved the 4 to the center or the 8 in 4's position - i.e. So for example, we'd assume 1 is at the correct position. How do you proceed?Ī simple approach would be to start in order, top -> bottom and left -> right. The two remaining balls (a stripe and a solid) don't matter.Īssume you just finished a game, gather the balls, put them in the rack and proceed to arrange them to start a new one. the 8-ball must be in the center, and along the sides the stripes and the solids must alternate. Since racking of billiard balls for the 8-ball game can be done under multiple rules, here's the racking I refer to:
