I have the following problem to solve in Mathematica, but (maybe because of my inexperience) it seems quite a really one to code properly.

Given a line $y=mx+q$ with $q>0$ and $m<0$, this intersects the positive $x$-axis and a positive $y$-axis to form a rectangular triangle in the first quadrant.

I would like to find an algorithm that will allow me to write all the integral points $(x,y)$ contained inside of such triangle (or on in boundary) in function of $m$ and $q$. With integral points I mean points such that $x$ and $y$ are integer numbers. Furthermore (an this is crucial) I would like to have the set of coordinates of such output points as entries of a list.

So far I can solve the problem via a nested "while cycle" but the output is not a list, rather it is many cells, each one printing the coordinates of one point inside.

Any suggestions?


closed as off-topic by MarcoB, corey979, Feyre, C. E., Edmund Feb 3 '17 at 13:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, corey979, Feyre, C. E., Edmund
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    $\begingroup$ Like this: {x, y} /. {ToRules[Reduce[y < 11 - 7 x && x > 0 && y > 0, {x, y}, Integers]]}? $\endgroup$ – J. M. will be back soon Feb 1 '17 at 1:34
  • $\begingroup$ Run J. M.'s code and then (for fun): Graphics[Point /@ %] $\endgroup$ – David G. Stork Feb 1 '17 at 1:54
  • 1
    $\begingroup$ Closely related question: mathematica.stackexchange.com/q/135141/3066 $\endgroup$ – m_goldberg Feb 1 '17 at 4:45
  • $\begingroup$ this one is about trivial to do directly as well Flatten[Table[ {x, y}, {x, 0, -q/m} , {y, 0, m x + q }], 1] $\endgroup$ – george2079 Feb 1 '17 at 21:50

Browse other questions tagged or ask your own question.