Given 7 pennies (1-cent coin), 5 nickels (5-cents), 3 dimes (10-cents), and 3 quarters (25-cents), list all ways to change 75 cents.
Assign a procedure that converts a Vector of the number of coins to a string. The contents of the Vector are the number of pennies, nickels, dimes, and quarters, in that order.
>
|
Change := proc(V)
local i;
sprintf("%d pennies + %d nickels "
"+ %d dimes + %d quarters "
"= 75 cents"
, seq(i, i=V));
end proc:
|
Assign a predicate that returns true if the Vector V has the exact change.
Iterate through all all possibilities, accepting those that are exact, and transforming the Vector to the desired string.
5 pennies + 4 nickels + 0 dimes + 2 quarters = 75 cents
5 pennies + 2 nickels + 1 dimes + 2 quarters = 75 cents
0 pennies + 3 nickels + 1 dimes + 2 quarters = 75 cents
5 pennies + 0 nickels + 2 dimes + 2 quarters = 75 cents
0 pennies + 1 nickels + 2 dimes + 2 quarters = 75 cents
| |