I'm trying to find a mathematician formula to avoid a counter that increment 1 step by step for any loops (any number for first element, last element and increment).
Example 1 (one for loop):
MIN=first element, MAX=last element and HOP=increment (variable i)
with counter:
c = 1;
for i = MIN:HOP:MAX
c = c + 1;
end
without counter:
for i = MIN:HOP:MAX
c = floor((i-MIN)/HOP) + 1;
end
Example 2 (two for loops):
MINi=first element, MAXi=last element and HOPi=increment (variable i)
MINj=first element, MAXj=last element and HOPj=increment (variable j)
with counter:
c = 1;
for i = MINi:HOPi:MAXi
for j = MINj:HOPj:MAXj
c = c + 1;
end
end
without counter:
for i = MINi:HOPi:MAXi
for j = MINj:HOPj:MAXj
x = (floor((i-MINi)/HOPi)+1);
y = (floor((j-MINj)/HOPj)+1);
c = x*y+(x-(floor((MAXi-MINi)/HOPi)+1))*((floor((MAXj-MINj)/HOPj)+1)-y);
end
end
Any simplification for c formula with two for loops?
Any formula for find c with k for loops, c(k)?