I am making a code in which a sum of the initial number stays in a certain range without exceeding 10000, neither of them two, one is the sum of the first +123, but for some reason, 2500 results (customers) do not come out, they only come out 2459
The initial number is 5000, and at no time can it exceed 10,000, the operation consists of X and X+123, but I have only achieved 2439 results
What error occurs?
clientes = 2500
base = 5000
sumport = 124
portase = {}
for i=1, clientes do
str = "no"
--formula = math.floor(base+((i*sumport)/53)) --2000 clients
formula = 5000+( ( math.floor( i / 123 ) ) * ( 123 ) ) + (i-1) --New formule
portase[formula+123] = true
ASE = formula+123
if ASE > 10000 then
break
end
if portase[formula] then
str = "YES YES YES YES"
end
ASE = formula+123
print ("CLIENT: "..i..", PORT: "..formula..", ASE: "..ASE..", MATCHES WITH OTHER? "..str)
portase[formula] = true
end
Because in iteration 2460 the value of
ASE
is equal to 10042 and it enters your conditionif
that has inside abreak
this ends the FOR and does not print any more values.I have reformulated your code but I have kept the formula that you have used with
math.floor
to see what you get with it:The code can be summarized according to what I understand you are looking for through the following scheme:
Regarding the discrete jumps you want to achieve with the formula you used, I suggest you review some modular arithmetic so that you are on the right track in the development of your code.
Regarding the expression that I used in
str = ASE == limite and "YES YES YES YES" or "no"
I suggest that you see this post that I made about that type of notation.I also removed from your original code the following statement:
This is because according to the execution order it was in, it would always take
portase[formula]
the value of,nil
that is, it would neverstr
be"YES YES YES YES"
Now if what you are looking for is that the match is the PORT of the client "n" equal to the ASE of the client "n-123" , from Client 124 (its Port:5123 would be equal to the ASE:5123 of Client 1 - see diagram above -) in such a case the
str
could also be defined like this:It would be very easy to put a conditional for that situation as well. The complexity of your question really resides, as I see it, in the formula that you will use to define the discrete jumps.