How do I transform this algorithm in a mathematical formula

108 Views Asked by At

The algorithm is in python but is easy enough to understand:

for i in range(5):
        for j in range(10):
                for k in range(20):
                        res = 20*i + 10*j + 5*k
                        if (res == 100):
                                print("{} notas de 20\n{} notas de 10\n{} notas de 5\n".format(i,j,k))

May I please to know a formule to give the manners to sum R\$100 with notes of R\$5, R\$10 and R\$20.

And another question: Would you write a formule to transform the repeat node 'for x in range(20)' into mathematics?

Thanks folks

Edit
May I please to know how i show the number of possible results of the python algoritm through this domain (the mathematical domain supposed in the algorithm).

Edit
Need a answer in mathematical form.

2

There are 2 best solutions below

1
On

I guess I would say that you're defining the set $\{i \in \mathbb{Z}_5, j \in \mathbb{Z}_{10}, k \in \mathbb{Z}_{20} | 20i + 10j + 5k = 100\}$, although there are a few different ways you could express the idea that $i$ is a positive integer less than 5.

3
On

You are solving the equation $$ 20i + 10j + 5k = 100 $$ for $i$, $j$, $k$, $\in \mathbb{Z}^{+}$, with the domains $$ i \in \left[1, 5\right], \quad j \in \left[1, 10\right], \quad k \in \left[1, 20\right]. $$

Addendum

Here is a basic example in 2 dimensions: $$ x + 2y = 16 $$ The solution is the blue line, the integer solutions are marked with red dots. Solutions with 0 values are excluded as in your problem.

Note: it may be easier to deal with the equivalent form $4i + 2j + k = 20$ for the original problem.

A simpler problem