Skip to main content
added 164 characters in body
Source Link
Domen
  • 33.4k
  • 3
  • 47
  • 66

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line, x, y},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -13}, {17, -11}, {18, -9}, {19, -7}, {20, -5}, 
    {21, -3}, {22, -1}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)

Or an even simpler solution, as given by @ydd:

findIntegerSolutions[a_, b_] := 
   Module[{x}, SolveValues[x ∈ Line[{a, b}], x, Integers]]

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -13}, {17, -11}, {18, -9}, {19, -7}, {20, -5}, 
    {21, -3}, {22, -1}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line, x, y},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -13}, {17, -11}, {18, -9}, {19, -7}, {20, -5}, 
    {21, -3}, {22, -1}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)

Or an even simpler solution, as given by @ydd:

findIntegerSolutions[a_, b_] := 
   Module[{x}, SolveValues[x ∈ Line[{a, b}], x, Integers]]
deleted 6 characters in body
Source Link
Domen
  • 33.4k
  • 3
  • 47
  • 66

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x2x - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -1513}, {17, -1511}, {18, -159}, {19, -157}, {20, -155}, 
    {21, -153}, {22, -151}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x2 - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -15}, {17, -15}, {18, -15}, {19, -15}, {20, -15}, 
    {21, -15}, {22, -15}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -13}, {17, -11}, {18, -9}, {19, -7}, {20, -5}, 
    {21, -3}, {22, -1}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)
Source Link
Domen
  • 33.4k
  • 3
  • 47
  • 66

Following the answer by Yves Klett on a practically identical question, this is easily computed via Solve (or any related equation-solving functions), you only have to be careful when you have a vertical line (ie. $x_1 = x_2$):

findIntegerSolutions[{x1_, y1_}, {x2_, y2_}] := Module[{line},
  line = If[x1 == x2, x == x1, y - y1 == (y2 - y1)/(x2 - x1) (x2 - x1)];
  SolveValues[line && {x} ∈ Interval[{x1, x2}] && {y} ∈ Interval[{y1, y2}], 
   {x, y}, Integers]
  ]

findIntegerSolutions[{45/2, 0}, {45/3, -45/3}]
(* {{15, -15}, {16, -15}, {17, -15}, {18, -15}, {19, -15}, {20, -15}, 
    {21, -15}, {22, -15}} *)

findIntegerSolutions[{21, 0}, {21, 10/5}]
(* {{21, 0}, {21, 1}, {21, 2}} *)