Find integer couples (x, y) for an equation ax+(x-b)y = c

Apr 2016
9
6
France
Considering that a, b and c are constant integers, is there a small algorithm to find the couple (x, y) with y the closest to (and greater than or equal to) d ? WolframAlpha can give me results, but I have no idea how it found them.

For the case in itself : I'm making a GUI for a video game, and I would like to list, on different lines, the maps that the user can choose. I want the gap between each line to always be the same, and greater than a constant. I know the size of the GUI and the font height. Thus I get the following equation :

GUIHeight - ((#Lines*FontHeight)+((#Lines-1)*GapSize) = 0,
or #Lines*FontHeight + (#Lines-1)*GapSize = GUIHeight, with GapSize >= MinGapSize

The goal is to find the gap the closest to a constant limit in pixels, with the number of lines coming with it, in function of different font sizes (that are known) and the size of the GUI.

The lines and the gaps have to fill the whole GUI.

Thank you in advance ! : )
 
Last edited:
  • Like
Reactions: 1 person

Denis

Math Team
Oct 2011
14,592
1,026
Ottawa Ontario, Canada
Considering that a, b and c are constant integers, is there a small algorithm to find the couple (x, y) with y the closest to (and greater than or equal to) d ?
What d'heck is "d"?
 
  • Like
Reactions: 1 person

Denis

Math Team
Oct 2011
14,592
1,026
Ottawa Ontario, Canada
GUIHeight - ((#Lines*FontHeight)+((#Lines-1)*GapSize) = 0,
You're missing a ")"; I assume it belongs at end:
GUIHeight - ((#Lines*FontHeight)+((#Lines-1)*GapSize)) = 0

h = GUIHeight
n = #Lines
f = FontHeight
g = GapSize)

h - [n*f + (n-1)*g] = 0

Is that what you mean?
And which variable do you want to solve for?
 
  • Like
Reactions: 1 person
Apr 2016
9
6
France
Yep. I did forgot a parenthesis where you pointed it out. But that's just the context. It's really the first paragraph that is my request :). And it is for GapSize and #Lines variables (as said in the last paragraph).
 
Last edited:
  • Like
Reactions: 1 person

Denis

Math Team
Oct 2011
14,592
1,026
Ottawa Ontario, Canada
Mon Dieu Bertrand...recite le chapelet 3 fois :eek:

So you want to solve this equation for g and for n:
h - [n*f + (n-1)*g] = 0

Correct?
 
  • Like
Reactions: 1 person

Denis

Math Team
Oct 2011
14,592
1,026
Ottawa Ontario, Canada
Is my english so incomprehensible :( ?
No....your English is better than mine.

Equation:
h - [n*f + (n-1)*g] = 0

Solve for g:
h - n*f - (n-1)*g = 0

(n-1)g = h - nf

g = (h - nf) / (n-1)

Solve for n:
nf + ng - g = h

n(f+g) = h + g

n = (h+g) / (f+g)

Bin tabarnak!!
 
  • Like
Reactions: 1 person
Apr 2016
9
6
France
Yes... I know... The thing is that you know neither the number of lines, nor the gap size. Is only know the size of one line (FontHeight) and the total size (GUIHeight). The title of the thread and the first paragraph of my first post are my really request, just forget what I said after (it was just a contextualization). Sorry to have wasted your time.

I will reword my request entirely.

What is the simpliest algorithm (for example used by WolframAlpha) that allow you to find every couples of integers (x, y) that can solve the equation ax+(x-b)y = c, with a, b and c constants there are known ?

It's kinda a Diophantine Equation, and I think the algorithm is something like the euclidian one.
 
Last edited:
  • Like
Reactions: 1 person