Dada una mesa de billar rectangular 
con lados de longitudes enteras m y n, 
una bola enviada con un ángulo de 45° 
desde una esquina acabará en otra 
esquina después de:

\frac{m + n}{MCD(m, n)}-2 \;  \;  \; rebotes.

n = 12 (slider from 1 to 12, step 1)
m = 9 (slider from 1 to 12, step 1)
A = (-4, 6)
B: A + (n, 0)
C: B - (0, m)
D: A - (0, m)
c1 = Segment(A, B)
c2 = Segment(B, C)
c3 = Segment(C, D)
c4 = Segment(D, A)
banda: {c1, c2, c3, c4}
P = Point(banda)
V: (1, 1)
v = Vector(V)
A1: P
B1: V
C1 = Line(A1, Vector[B1])
D1 = Sequence(Intersect[C1, banda(k)], k, 1, 4)
E1 = RemoveUndefined(D1)
F1 = Remove(E1, {A1})
G1: F1(1)
H1 = If(G1 ∈ c1, c1, G1 ∈ c2, c2, G1 ∈ c3, c3, c4)
I1 = Mirror(G1 + B1, H1)
A2: G1
B2: I1 - A2
C2 = Line(A2, Vector[B2])
D2 = Sequence(Intersect[C2, banda(k)], k, 1, 4)
E2 = RemoveUndefined(D2)
F2 = Remove(E2, {A2})
G2: F2(1)
H2 = If(G2 ∈ c1, c1, G2 ∈ c2, c2, G2 ∈ c3, c3, c4)
I2 = Mirror(G2 + B2, H2)
A3: G2
B3: I2 - A3
C3 = Line(A3, Vector[B3])
D3 = Sequence(Intersect[C3, banda(k)], k, 1, 4)
E3 = RemoveUndefined(D3)
F3 = Remove(E3, {A3})
G3: F3(1)
H3 = If(G3 ∈ c1, c1, G3 ∈ c2, c2, G3 ∈ c3, c3, c4)
I3 = Mirror(G3 + B3, H3)
A4: G3
B4: I3 - A4
C4 = Line(A4, Vector[B4])
D4 = Sequence(Intersect[C4, banda(k)], k, 1, 4)
E4 = RemoveUndefined(D4)
F4 = Remove(E4, {A4})
G4: F4(1)
H4 = If(G4 ∈ c1, c1, G4 ∈ c2, c2, G4 ∈ c3, c3, c4)
I4 = Mirror(G4 + B4, H4)
A5: G4
B5: I4 - A5
C5 = Line(A5, Vector[B5])
D5 = Sequence(Intersect[C5, banda(k)], k, 1, 4)
E5 = RemoveUndefined(D5)
F5 = Remove(E5, {A5})
G5: F5(1)
H5 = If(G5 ∈ c1, c1, G5 ∈ c2, c2, G5 ∈ c3, c3, c4)
I5 = Mirror(G5 + B5, H5)
A6: G5
B6: I5 - A6
C6 = Line(A6, Vector[B6])
D6 = Sequence(Intersect[C6, banda(k)], k, 1, 4)
E6 = RemoveUndefined(D6)
F6 = Remove(E6, {A6})
G6: F6(1)
H6 = If(G6 ∈ c1, c1, G6 ∈ c2, c2, G6 ∈ c3, c3, c4)
I6 = Mirror(G6 + B6, H6)
A7: G6
B7: I6 - A7
C7 = Line(A7, Vector[B7])
D7 = Sequence(Intersect[C7, banda(k)], k, 1, 4)
E7 = RemoveUndefined(D7)
F7 = Remove(E7, {A7})
G7: F7(1)
H7 = If(G7 ∈ c1, c1, G7 ∈ c2, c2, G7 ∈ c3, c3, c4)
I7 = Mirror(G7 + B7, H7)
A8: G7
B8: I7 - A8
C8 = Line(A8, Vector[B8])
D8 = Sequence(Intersect[C8, banda(k)], k, 1, 4)
E8 = RemoveUndefined(D8)
F8 = Remove(E8, {A8})
G8: F8(1)
H8 = If(G8 ∈ c1, c1, G8 ∈ c2, c2, G8 ∈ c3, c3, c4)
I8 = Mirror(G8 + B8, H8)
A9: G8
B9: I8 - A9
C9 = Line(A9, Vector[B9])
D9 = Sequence(Intersect[C9, banda(k)], k, 1, 4)
E9 = RemoveUndefined(D9)
F9 = Remove(E9, {A9})
G9: F9(1)
H9 = If(G9 ∈ c1, c1, G9 ∈ c2, c2, G9 ∈ c3, c3, c4)
I9 = Mirror(G9 + B9, H9)
A10: G9
B10: I9 - A10
C10 = Line(A10, Vector[B10])
D10 = Sequence(Intersect[C10, banda(k)], k, 1, 4)
E10 = RemoveUndefined(D10)
F10 = Remove(E10, {A10})
G10: F10(1)
H10 = If(G10 ∈ c1, c1, G10 ∈ c2, c2, G10 ∈ c3, c3, c4)
I10 = Mirror(G10 + B10, H10)
A11: G10
B11: I10 - A11
C11 = Line(A11, Vector[B11])
D11 = Sequence(Intersect[C11, banda(k)], k, 1, 4)
E11 = RemoveUndefined(D11)
F11 = Remove(E11, {A11})
G11: F11(1)
H11 = If(G11 ∈ c1, c1, G11 ∈ c2, c2, G11 ∈ c3, c3, c4)
I11 = Mirror(G11 + B11, H11)
A12: G11
B12: I11 - A12
C12 = Line(A12, Vector[B12])
D12 = Sequence(Intersect[C12, banda(k)], k, 1, 4)
E12 = RemoveUndefined(D12)
F12 = Remove(E12, {A12})
G12: F12(1)
H12 = If(G12 ∈ c1, c1, G12 ∈ c2, c2, G12 ∈ c3, c3, c4)
I12 = Mirror(G12 + B12, H12)
A13: G12
B13: I12 - A13
C13 = Line(A13, Vector[B13])
D13 = Sequence(Intersect[C13, banda(k)], k, 1, 4)
E13 = RemoveUndefined(D13)
F13 = Remove(E13, {A13})
G13: F13(1)
H13 = If(G13 ∈ c1, c1, G13 ∈ c2, c2, G13 ∈ c3, c3, c4)
I13 = Mirror(G13 + B13, H13)
A14: G13
B14: I13 - A14
C14 = Line(A14, Vector[B14])
D14 = Sequence(Intersect[C14, banda(k)], k, 1, 4)
E14 = RemoveUndefined(D14)
F14 = Remove(E14, {A14})
G14: F14(1)
H14 = If(G14 ∈ c1, c1, G14 ∈ c2, c2, G14 ∈ c3, c3, c4)
I14 = Mirror(G14 + B14, H14)
A15: G14
B15: I14 - A15
C15 = Line(A15, Vector[B15])
D15 = Sequence(Intersect[C15, banda(k)], k, 1, 4)
E15 = RemoveUndefined(D15)
F15 = Remove(E15, {A15})
G15: F15(1)
H15 = If(G15 ∈ c1, c1, G15 ∈ c2, c2, G15 ∈ c3, c3, c4)
I15 = Mirror(G15 + B15, H15)
A16: G15
B16: I15 - A16
C16 = Line(A16, Vector[B16])
D16 = Sequence(Intersect[C16, banda(k)], k, 1, 4)
E16 = RemoveUndefined(D16)
F16 = Remove(E16, {A16})
G16: F16(1)
H16 = If(G16 ∈ c1, c1, G16 ∈ c2, c2, G16 ∈ c3, c3, c4)
I16 = Mirror(G16 + B16, H16)
A17: G16
B17: I16 - A17
C17 = Line(A17, Vector[B17])
D17 = Sequence(Intersect[C17, banda(k)], k, 1, 4)
E17 = RemoveUndefined(D17)
F17 = Remove(E17, {A17})
G17: F17(1)
H17 = If(G17 ∈ c1, c1, G17 ∈ c2, c2, G17 ∈ c3, c3, c4)
I17 = Mirror(G17 + B17, H17)
A18: G17
B18: I17 - A18
C18 = Line(A18, Vector[B18])
D18 = Sequence(Intersect[C18, banda(k)], k, 1, 4)
E18 = RemoveUndefined(D18)
F18 = Remove(E18, {A18})
G18: F18(1)
H18 = If(G18 ∈ c1, c1, G18 ∈ c2, c2, G18 ∈ c3, c3, c4)
I18 = Mirror(G18 + B18, H18)
A19: G18
B19: I18 - A19
C19 = Line(A19, Vector[B19])
D19 = Sequence(Intersect[C19, banda(k)], k, 1, 4)
E19 = RemoveUndefined(D19)
F19 = Remove(E19, {A19})
G19: F19(1)
H19 = If(G19 ∈ c1, c1, G19 ∈ c2, c2, G19 ∈ c3, c3, c4)
I19 = Mirror(G19 + B19, H19)
A20: G19
B20: I19 - A20
C20 = Line(A20, Vector[B20])
D20 = Sequence(Intersect[C20, banda(k)], k, 1, 4)
E20 = RemoveUndefined(D20)
F20 = Remove(E20, {A20})
G20: F20(1)
H20 = If(G20 ∈ c1, c1, G20 ∈ c2, c2, G20 ∈ c3, c3, c4)
I20 = Mirror(G20 + B20, H20)
A21: G20
B21: I20 - A21
C21 = Line(A21, Vector[B21])
D21 = Sequence(Intersect[C21, banda(k)], k, 1, 4)
E21 = RemoveUndefined(D21)
F21 = Remove(E21, {A21})
G21: F21(1)
H21 = If(G21 ∈ c1, c1, G21 ∈ c2, c2, G21 ∈ c3, c3, c4)
I21 = Mirror(G21 + B21, H21)
A22: G21
B22: I21 - A22
C22 = Line(A22, Vector[B22])
D22 = Sequence(Intersect[C22, banda(k)], k, 1, 4)
E22 = RemoveUndefined(D22)
F22 = Remove(E22, {A22})
G22: F22(1)
H22 = If(G22 ∈ c1, c1, G22 ∈ c2, c2, G22 ∈ c3, c3, c4)
I22 = Mirror(G22 + B22, H22)
A23: G22
B23: I22 - A23
C23 = Line(A23, Vector[B23])
D23 = Sequence(Intersect[C23, banda(k)], k, 1, 4)
E23 = RemoveUndefined(D23)
F23 = Remove(E23, {A23})
G23: F23(1)
H23 = If(G23 ∈ c1, c1, G23 ∈ c2, c2, G23 ∈ c3, c3, c4)
I23 = Mirror(G23 + B23, H23)
A24: G23
B24: I23 - A24
C24 = Line(A24, Vector[B24])
D24 = Sequence(Intersect[C24, banda(k)], k, 1, 4)
E24 = RemoveUndefined(D24)
F24 = Remove(E24, {A24})
G24: F24(1)
H24 = If(G24 ∈ c1, c1, G24 ∈ c2, c2, G24 ∈ c3, c3, c4)
I24 = Mirror(G24 + B24, H24)
A25: G24
B25: I24 - A25
C25 = Line(A25, Vector[B25])
D25 = Sequence(Intersect[C25, banda(k)], k, 1, 4)
E25 = RemoveUndefined(D25)
F25 = Remove(E25, {A25})
G25: F25(1)
H25 = If(G25 ∈ c1, c1, G25 ∈ c2, c2, G25 ∈ c3, c3, c4)
I25 = Mirror(G25 + B25, H25)
A26: G25
B26: I25 - A26
C26 = Line(A26, Vector[B26])
D26 = Sequence(Intersect[C26, banda(k)], k, 1, 4)
E26 = RemoveUndefined(D26)
F26 = Remove(E26, {A26})
G26: F26(1)
H26 = If(G26 ∈ c1, c1, G26 ∈ c2, c2, G26 ∈ c3, c3, c4)
I26 = Mirror(G26 + B26, H26)
A27: G26
B27: I26 - A27
C27 = Line(A27, Vector[B27])
D27 = Sequence(Intersect[C27, banda(k)], k, 1, 4)
E27 = RemoveUndefined(D27)
F27 = Remove(E27, {A27})
G27: F27(1)
H27 = If(G27 ∈ c1, c1, G27 ∈ c2, c2, G27 ∈ c3, c3, c4)
I27 = Mirror(G27 + B27, H27)
A28: G27
B28: I27 - A28
C28 = Line(A28, Vector[B28])
D28 = Sequence(Intersect[C28, banda(k)], k, 1, 4)
E28 = RemoveUndefined(D28)
F28 = Remove(E28, {A28})
G28: F28(1)
H28 = If(G28 ∈ c1, c1, G28 ∈ c2, c2, G28 ∈ c3, c3, c4)
I28 = Mirror(G28 + B28, H28)
A29: G28
B29: I28 - A29
C29 = Line(A29, Vector[B29])
D29 = Sequence(Intersect[C29, banda(k)], k, 1, 4)
E29 = RemoveUndefined(D29)
F29 = Remove(E29, {A29})
G29: F29(1)
H29 = If(G29 ∈ c1, c1, G29 ∈ c2, c2, G29 ∈ c3, c3, c4)
I29 = Mirror(G29 + B29, H29)
A30: G29
B30: I29 - A30
C30 = Line(A30, Vector[B30])
D30 = Sequence(Intersect[C30, banda(k)], k, 1, 4)
E30 = RemoveUndefined(D30)
F30 = Remove(E30, {A30})
G30: F30(1)
H30 = If(G30 ∈ c1, c1, G30 ∈ c2, c2, G30 ∈ c3, c3, c4)
I30 = Mirror(G30 + B30, H30)
A31: G30
B31: I30 - A31
C31 = Line(A31, Vector[B31])
D31 = Sequence(Intersect[C31, banda(k)], k, 1, 4)
E31 = RemoveUndefined(D31)
F31 = Remove(E31, {A31})
G31: F31(1)
H31 = If(G31 ∈ c1, c1, G31 ∈ c2, c2, G31 ∈ c3, c3, c4)
I31 = Mirror(G31 + B31, H31)
A32: G31
B32: I31 - A32
C32 = Line(A32, Vector[B32])
D32 = Sequence(Intersect[C32, banda(k)], k, 1, 4)
E32 = RemoveUndefined(D32)
F32 = Remove(E32, {A32})
G32: F32(1)
H32 = If(G32 ∈ c1, c1, G32 ∈ c2, c2, G32 ∈ c3, c3, c4)
I32 = Mirror(G32 + B32, H32)
A33: G32
B33: I32 - A33
C33 = Line(A33, Vector[B33])
D33 = Sequence(Intersect[C33, banda(k)], k, 1, 4)
E33 = RemoveUndefined(D33)
F33 = Remove(E33, {A33})
G33: F33(1)
H33 = If(G33 ∈ c1, c1, G33 ∈ c2, c2, G33 ∈ c3, c3, c4)
I33 = Mirror(G33 + B33, H33)
A34: G33
B34: I33 - A34
C34 = Line(A34, Vector[B34])
D34 = Sequence(Intersect[C34, banda(k)], k, 1, 4)
E34 = RemoveUndefined(D34)
F34 = Remove(E34, {A34})
G34: F34(1)
H34 = If(G34 ∈ c1, c1, G34 ∈ c2, c2, G34 ∈ c3, c3, c4)
I34 = Mirror(G34 + B34, H34)
A35: G34
B35: I34 - A35
C35 = Line(A35, Vector[B35])
D35 = Sequence(Intersect[C35, banda(k)], k, 1, 4)
E35 = RemoveUndefined(D35)
F35 = Remove(E35, {A35})
G35: F35(1)
H35 = If(G35 ∈ c1, c1, G35 ∈ c2, c2, G35 ∈ c3, c3, c4)
I35 = Mirror(G35 + B35, H35)
A36: G35
B36: I35 - A36
C36 = Line(A36, Vector[B36])
D36 = Sequence(Intersect[C36, banda(k)], k, 1, 4)
E36 = RemoveUndefined(D36)
F36 = Remove(E36, {A36})
G36: F36(1)
H36 = If(G36 ∈ c1, c1, G36 ∈ c2, c2, G36 ∈ c3, c3, c4)
I36 = Mirror(G36 + B36, H36)
A37: G36
B37: I36 - A37
C37 = Line(A37, Vector[B37])
D37 = Sequence(Intersect[C37, banda(k)], k, 1, 4)
E37 = RemoveUndefined(D37)
F37 = Remove(E37, {A37})
G37: F37(1)
H37 = If(G37 ∈ c1, c1, G37 ∈ c2, c2, G37 ∈ c3, c3, c4)
I37 = Mirror(G37 + B37, H37)
A38: G37
B38: I37 - A38
C38 = Line(A38, Vector[B38])
D38 = Sequence(Intersect[C38, banda(k)], k, 1, 4)
E38 = RemoveUndefined(D38)
F38 = Remove(E38, {A38})
G38: F38(1)
H38 = If(G38 ∈ c1, c1, G38 ∈ c2, c2, G38 ∈ c3, c3, c4)
I38 = Mirror(G38 + B38, H38)
A39: G38
B39: I38 - A39
C39 = Line(A39, Vector[B39])
D39 = Sequence(Intersect[C39, banda(k)], k, 1, 4)
E39 = RemoveUndefined(D39)
F39 = Remove(E39, {A39})
G39: F39(1)
H39 = If(G39 ∈ c1, c1, G39 ∈ c2, c2, G39 ∈ c3, c3, c4)
I39 = Mirror(G39 + B39, H39)
A40: G39
B40: I39 - A40
C40 = Line(A40, Vector[B40])
D40 = Sequence(Intersect[C40, banda(k)], k, 1, 4)
E40 = RemoveUndefined(D40)
F40 = Remove(E40, {A40})
G40: F40(1)
H40 = If(G40 ∈ c1, c1, G40 ∈ c2, c2, G40 ∈ c3, c3, c4)
I40 = Mirror(G40 + B40, H40)
trayectoria = PolyLine(A1:A40)
verSolución = true
l1: {Polygon[A, B, C, D]}
rebotes = First(A2:A40, (m + n) / GCD[m, n] - 2)