This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A289236 #20 Aug 12 2018 17:28:07 %S A289236 1,2,2,3,1,3,4,4,4,4,5,2,1,2,5,6,6,6,6,6,6,7,3,7,1,7,3,7,8,8,2,8,8,2, %T A289236 8,8,9,4,9,4,1,4,9,4,9,10,10,10,10,10,10,10,10,10,10,11,5,3,2,11,1,11, %U A289236 2,3,5,11,12,12,12,12,12,12,12,12,12,12,12,12 %N A289236 Square array a(p,q) read by antidiagonals: a(p,q) = the number of line segments that constitute the trajectory of a billiard ball on a pool table with dimensions p X q, before the ball reaches a corner. %C A289236 The billiard game considered here is an idealized one: the pool table is a rectangle with vertices (0,0), (p,0), (p,q), (0, q); the ball is shrunk to a point and is launched from vertex (0,0) with initial velocity vector (1,1); collisions are supposed elastic and friction is supposed nonexistent, so that the ball can never stop on the table; when the ball bounces, the angle of reflection is equal to the angle of incidence; the ball can only exit through a vertex. %C A289236 a(p,q) counts the line segments that constitute the trajectory. %F A289236 a(p,q) = (p + q) / gcd(p, q) - 1. %e A289236 In a square-shaped pool table, the ball just crosses diagonally. a(p,p)=1. %e A289236 In a pool table of dimensions 2 X 1, the ball bounces once and exits. a(2,1)=2. %e A289236 The square array a(p,q) begins: %e A289236 1 2 3 4 5 6 7 %e A289236 2 1 4 2 6 3 8 %e A289236 3 4 1 6 7 2 9 %e A289236 4 2 6 1 8 4 10 %e A289236 5 6 7 8 1 10 11 %e A289236 6 3 2 4 10 1 12 %e A289236 7 8 9 10 11 12 1 %o A289236 (Java) %o A289236 long a(long p, long q) { %o A289236 long i = 0, x = 0, y = 0, dx = +1, dy = +1, s = 1; %o A289236 while ((((x % p) != 0) || ((y % q) != 0)) || (i == 0)) { %o A289236 i ++; long xx = x + dx; long yy = y + dy; %o A289236 boolean xok = (0 <= xx) && (xx <= p); %o A289236 boolean yok = (0 <= yy) && (yy <= q); %o A289236 if (xok && yok) { x = xx; y = yy; } %o A289236 else { s ++; %o A289236 if (! xok) { dx = -dx; } %o A289236 if (! yok) { dy = -dy; } %o A289236 }} return s; } %Y A289236 Cf. A059026 (the triangle version). %K A289236 nonn,tabl %O A289236 1,2 %A A289236 _Luc Rousseau_, Jun 28 2017