Anonymous user
Count the coins: Difference between revisions
→{{header|Scala}}
m (added whitespace to the task's preamble, added numbered bullet points, added a link.) |
|||
Line 1,993:
.....
242 ways to make a buck</pre>
=={{header|SAS}}==
Generate the solutions using CLP solver in SAS/OR:
<lang sas>/* call OPTMODEL procedure in SAS/OR */
proc optmodel;
/* declare set and names of coins */
set COINS = {1,5,10,25};
str name {COINS} = ['penny','nickel','dime','quarter'];
/* declare variables and constraint */
var NumCoins {COINS} >= 0 integer;
con Dollar:
sum {i in COINS} i * NumCoins[i] = 100;
/* call CLP solver */
solve with CLP / findallsolns;
/* write solutions to SAS data set */
create data sols(drop=s) from [s]=(1.._NSOL_) {i in COINS} <col(name[i])=NumCoins[i].sol[s]>;
quit;
/* print all solutions */
proc print data=sols;
run;</lang>
Output:
<pre>
Obs penny nickel dime quarter
1 100 0 0 0
2 95 1 0 0
3 90 2 0 0
4 85 3 0 0
5 80 4 0 0
...
238 5 2 1 3
239 0 3 1 3
240 5 0 2 3
241 0 1 2 3
242 0 0 0 4
</pre>
=={{header|Scala}}==
|