Provo a spiegarmi meglio rendendo le cose un po' più concrete.
esempioTanto per fissare le idee, consideriamo il caso $m= 6$.
In questo caso la funzione $\text{cont}_m(\cdot,\cdot)=\text{cont}_6(\cdot,\cdot)$ è data dalla seguente lookup table
\[
\begin{array}{cc|c}
g & h & \text{cont}_6 \\
\hline
1 & 1 & 1 \\
1 & 2 & 2 \\
1 & 3 & 3 \\
1 & 4 & 4 \\
1 & 5 & 5 \\
1 & 6 & 6 \\
2 & 2 & 7 \\
2 & 3 & 8 \\
2 & 4 & 9 \\
2 & 5 & 10 \\
2 & 6 & 11
\end{array}
\quad
\begin{array}{cc|c}
g & h & \text{cont}_6 \\
\hline
3 & 3 & 12 \\
3 & 4 & 13 \\
3 & 5 & 14 \\
3 & 6 & 15 \\
4 & 4 & 16 \\
4 & 5 & 17 \\
4 & 6 & 18 \\
5 & 5 & 19 \\
5 & 6 & 20 \\
6 & 6 & 21
\end{array}
\]
magari può essere utile rappresentare $\text{cont}_6(\cdot, \cdot)$ in forma "triangolare"
\[\begin{array}{c |cccccc}
\text{g\h} & 1 & 2 & 3 & 4 & 5 & 6 \\
\hline
1 & 1 & 2 & 3 & 4 & 5 & 6\\
2 & & 7 & 8 & 9 & 10 & 11\\
3 & & & 12 & 13 & 14 & 15\\
4 & & & & 16 & 17 & 18\\
5 & & & & & 19 & 20\\
6 & & & & & & 21\\
\end{array}
\]
osservazioneper il seguente ciclo
- Codice:
cont = 0
for g = 1, ...,m
for h = 1, ...,m
cont = cont +1
end for
end for
l'espressione esplicita del contatore è la seguente
\begin{equation}\text{cont}_m(g,h)=m(g-1)+h\end{equation}