How to resolve the algorithm Count the coins step by step in the SETL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Count the coins step by step in the SETL programming language
Table of Contents
Problem Statement
There are four types of common coins in US currency:
There are six ways to make change for 15 cents:
How many ways are there to make change for a dollar using these common coins? (1 dollar = 100 cents).
Less common are dollar coins (100 cents); and very rare are half dollars (50 cents). With the addition of these two coins, how many ways are there to make change for $1000? (Note: the answer is larger than 232).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Count the coins step by step in the SETL programming language
Source code in the setl programming language
program count_the_coins;
print(count([1, 5, 10, 25], 100));
print(count([1, 5, 10, 25, 50, 100], 1000 * 100));
proc count(coins, n);
tab := {[0, 1]};
loop for coin in coins do
loop for i in [coin..n] do
tab(i) +:= tab(i - coin) ? 0;
end loop;
end loop;
return tab(n);
end proc;
end program;
You may also check:How to resolve the algorithm Conditional structures step by step in the Ruby programming language
You may also check:How to resolve the algorithm The sieve of Sundaram step by step in the Java programming language
You may also check:How to resolve the algorithm Gaussian primes step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Recaman's sequence step by step in the Lua programming language
You may also check:How to resolve the algorithm Remove duplicate elements step by step in the zkl programming language