Ok, I’ll admit I was a bit late with this one – this was something I worked on over 2 years ago; it started of as a school maths question that kinda got out of hand. The question was something like this:

If you set up a billiards table, of dimensions MxN, and fire a ball at a 45 degree angle from the bottom left, which pocket will it fall into? (assume that the side pockets are taken out so there are only corner ones)

In this example, the ball goes out the bottom right pocket; but it doesn’t always. So how do we figure out which one goes out where?

## Which pocket will an MxN table take the ball to?

To answer this question, you start by changing the table’s dimensions, removing all shared factors between M and N untill they are coprime (they share no factors). Why? Well, a 1×3 and 2×6 table are going to be exactly the same, as the ratio of the sides is the same. When you’ve taken out all shared factors, you’ll find your numbers fit 3 categories:

### 1 – Both dimensions M and N are odd

In this situation, the ball will go out the top right.

### 2 – M is odd, N is even

In this situation, the ball goes out the bottom right.

### 3 – M is even, N is odd

In this situation, the ball goes to the top left.

You may notice there is no “both even” category, because if they are both even you can divide both sides by two and reduce it to one of the other categories. You may also notice that the ball can never exit via the bottom left pocket it starts in – there is simply no left over possibility to cover this option.

You can actually optimize this process significantly – finding all prime factors is quite hard; but you can shortcut it. Let’s define a (totally off the cuff) function, the evenness of a number, as the number of times it can be divided by two. So twelve has an evenness of 2, for example. Essentially, we just want to find if M and N have the same evenness, or if one has more than the other. So, all you have to do is keep dividing each dimension by two until one becomes odd – then you can simply compare to the rules above.

For example – 12×36. Both sides are even, so we divide by two to get 6×18. still even, so we divide again to get 3×9. Now we have at least one non-even value, so we can compare to the rules above.

## Ok, but where’s the pruff?

The core of the proof is the idea that you can represent the bounces of the billiard ball by mirroring the MxN table over and over again, essentially reflecting the table each bounce instead of reflecting the ball until you get somewhere between an MxN table (if M=N), and an MNxMN (if M or N are coprime) table.

First, here’s how you represent a bounce. When the ball hits a surface, instead of showing the ball bouncing like this:

You reflect the table at the point it hits the wall, and just show the ball travelling right through:

Essentially, the idea is to keep doing this process at every reflection, so instead of having an MxN grid with the ball bouncing everywhere, it turns into a larger grid where the ball appears to go straight from the bottom left to top right.

Since 3 and 4 are coprime, it will turn into a 12×12 grid, which looks something like this:

It’s pretty obvious that with this path, the ball will always leave via the top right – but the top right in this new table isn’t necessarily the same top right as in the original. So the question “which pocket does it exit through” can be rephrased as “what corner is the top right of the grid”. I’ve colour coded the corners in this example so you can see. The pattern is pretty obvious – the corners just alternate, going across or going down. All the green corners are the bottom left in the original grid, the purple is bottom right, and so on.

So, how do you figure out which corner? the first step is to figure out how many times the table has been flipped, both across the page and up and down. This is the part where we need to remove all of the shared factors of the two, so that we have the equivalent PxQ table, with the same ratio, where P and Q are coprime. This means that our mirrored table will be PQxPQ; as such, it will be reflected “P” times, left to right, and “Q” times upwards. So if P is even, then the final reflection going left to right will be backwards:

And so the “top right” is actually going to be top or bottom left! In a similar fashion, if “Q” is even, then what you would think of as the “top right” is actually going to be bottom right or left. If you combine these two factors, then you end up with the rules near the top of the post.

I realise that this doesn’t prove the little shortcut I showed. Maybe you could try and prove it!

(No, that doesn’t mean i’m too lazy to do it)

(Ok maybe a little)

## One last thing

I made a program to draw these tables in Kturtle.

```reset

spritehide

\$in1 = ask "What is the x value?"

\$in2 = ask "What is the y value?"

\$grid = ask "Do you want a grid?"

\$smaller_value = 1

if \$in1 < \$in2 {

\$smaller_value = \$in1

}

else {

\$smaller_value = \$in2

}

canvassize \$in1*40, \$in2*40

\$linelength = \$in1*\$in2

\$hcf = 1

for \$divisor = 2 to \$in1 {

\$mod1 = mod \$in1,\$divisor

\$mod2 = mod \$in2,\$divisor

if \$mod1 == 0 and \$mod2 == 0 {

\$hcf = \$divisor

}

}

}

\$linelength = \$linelength/\$hcf

go 0,0

turnleft 90

\$iteration = 1

if \$grid == "yes" {

repeat \$in1{

repeat \$in2{

repeat 4{

turnleft 90

forward 40

}

turnleft 90

forward 40

turnright 90

}

go \$iteration*40,0

\$iteration = \$iteration + 1

}

}

go 0,\$in2*40

dir 45

\$turtle_x = 0

\$turtle_y = 0

\$x_dir = 1

\$y_dir = 1

\$dar = 0

\$colour1 = random 0,255

\$colour2 = random 0,255

\$colour3 = random 0,255

forward 56.568542495

\$turtle_x = \$turtle_x + \$x_dir

\$turtle_y = \$turtle_y + \$y_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

repeat \$linelength-1 {

pencolor \$colour1, \$colour2, \$colour3

\$colour1 = random 0,255

\$colour2 = random 0,255

\$colour3 = random 0,255

\$dar = \$dar + 1

if \$turtle_y == 0 {

if \$x_dir == 1 {

turnleft 90

}

else {

turnright 90

}

forward 56.568542495

#print \$turtle_y

\$y_dir = 1

\$turtle_y = \$turtle_y + \$y_dir

\$turtle_x = \$turtle_x + \$x_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

}

else if \$turtle_x == 0 {

if \$y_dir == 1 {

turnright 90

}

else {

turnleft 90

}

forward 56.568542495

\$x_dir = 1

\$turtle_x = \$turtle_x + \$x_dir

\$turtle_y = \$turtle_y + \$y_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

}

else if \$turtle_x < \$in1 {

if \$turtle_y < \$in2 {

forward 56.568542495

\$turtle_x = \$turtle_x + \$x_dir

\$turtle_y = \$turtle_y + \$y_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

}

else if \$turtle_y == \$in2 {

if \$x_dir == 1 {

turnright 90

}

else {

turnleft 90

}

forward 56.568542495

\$y_dir = -1

\$turtle_y = \$turtle_y + \$y_dir

\$turtle_x = \$turtle_x + \$x_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

}

}

else if \$turtle_x == \$in1 {

if \$y_dir == 1 {

turnleft 90

}

else {

turnright 90

}

forward 56.568542495

\$x_dir = -1

\$turtle_x = \$turtle_x + \$x_dir

\$turtle_y = \$turtle_y + \$y_dir

#print \$turtle_x

turnright 180

#print \$turtle_y

turnright 180

}

}```