In a dotted 2d grid, lines can be drawn between the dots. But every dot that the line touches breaks the line up into smaller lines. I want to be able to work out how many lines this bigger line is made of, assuming the line starts at origin (0,0) and ends at the given x&y co-ordinates.
For example:
2 o o o
/
1 o o o
/
0 o o o
0 1 2
A line drawn to the point (2,2) crosses one point and splits into 2 different lines.
The table below shows how many lines a line splits into when drawn to the relevant point:
x y 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 1 1 1 1 1 1 1
2 2 1 2 1 2 1 2 1
3 3 1 1 3 1 1 3 1
4 4 1 2 1 4 1 2 1
5 5 1 1 1 1 5 1 1
6 6 1 2 3 2 1 6 1
7 7 1 1 1 1 1 1 7
Note that the top and left edges of the table are the x/y co-ordinates.
As you can see, there are many patterns in the table, but I cannot work out a formula of method to work out the value.
Any ideas?