@AcabaComigo
Fair enough;
" -1/2 < y/x < 1/2" corresponds to the gradient, under which this formula works. If you look at the images generated, it is clear there are 8 distinct regions, cutting the plane into 4 pairs of identical regions. This "-1/2 < y/x < 1/2" denotes the two "pizza slices" that are going left and right, towards x = minus infinite, and x = plus infinite, respectively.
Think of the function y = 1/2 * x, which is the same as saying that if we change the value of x by two squares, then the value of y will change by one square. All of the points that satisfy this are on a line of coordinate (0, 0), (1, 2), (2, 4), (3, 6), (4, 8), etc. These squares are all squares the Knight would go on, if it was going two squares to the right, and one square up, forever. He would stay on the line defined by y = 1/2 * x.
The lines defined by y = 1/2 * x and y = -1/2 * x:
If y = 1/2 * x, then clearly y/x = 1/2. This is what I mean when I say gradient, maybe you have another word for it, but to me it means how fast a line goes up.
When I say " -1/2 < y/x < 1/2", I can rewrite this as "-1/2 * x < y < 1/2 * x.
The point is, we are looking for x and y, such that y is underneath (<) the line defined by y = 1/2 * x, but OVER (>) the line defined by y = -1/2 * x. This is the region that I highlight here in gray / blue:
So this formula, ceiling(x/2) + (x+y) mod 2, only works in this region of space, and even then not for the smallest cases, when x and y are less than 4. However, it is easy to adapt this formula for the other 3 regions.
This || thing I added doesn't matter, I think. Thank you @ClaireWerk
Fair enough;
" -1/2 < y/x < 1/2" corresponds to the gradient, under which this formula works. If you look at the images generated, it is clear there are 8 distinct regions, cutting the plane into 4 pairs of identical regions. This "-1/2 < y/x < 1/2" denotes the two "pizza slices" that are going left and right, towards x = minus infinite, and x = plus infinite, respectively.
Think of the function y = 1/2 * x, which is the same as saying that if we change the value of x by two squares, then the value of y will change by one square. All of the points that satisfy this are on a line of coordinate (0, 0), (1, 2), (2, 4), (3, 6), (4, 8), etc. These squares are all squares the Knight would go on, if it was going two squares to the right, and one square up, forever. He would stay on the line defined by y = 1/2 * x.
The lines defined by y = 1/2 * x and y = -1/2 * x:
If y = 1/2 * x, then clearly y/x = 1/2. This is what I mean when I say gradient, maybe you have another word for it, but to me it means how fast a line goes up.
When I say " -1/2 < y/x < 1/2", I can rewrite this as "-1/2 * x < y < 1/2 * x.
The point is, we are looking for x and y, such that y is underneath (<) the line defined by y = 1/2 * x, but OVER (>) the line defined by y = -1/2 * x. This is the region that I highlight here in gray / blue:
So this formula, ceiling(x/2) + (x+y) mod 2, only works in this region of space, and even then not for the smallest cases, when x and y are less than 4. However, it is easy to adapt this formula for the other 3 regions.
This || thing I added doesn't matter, I think. Thank you @ClaireWerk