Combinations with repetitions: Difference between revisions

m ({{out}})
Line 97:
Total Donuts: 6
Total Tens: 220</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f COMBINATIONS_WITH_REPETITIONS.AWK
BEGIN {
n = split("iced,jam,plain",donuts,",")
for (i=1; i<=n; i++) {
for (j=1; j<=n; j++) {
if (donuts[i] < donuts[j]) {
key = sprintf("%s %s",donuts[i],donuts[j])
}
else {
key = sprintf("%s %s",donuts[j],donuts[i])
}
arr[key]++
}
}
cmd = "SORT"
for (i in arr) {
printf("%s\n",i) | cmd
choices++
}
close(cmd)
printf("choices = %d\n",choices)
exit(0)
}
</lang>
<p>output:</p>
<pre>
iced iced
iced jam
iced plain
jam jam
jam plain
plain plain
choices = 6
</pre>
 
=={{header|BBC BASIC}}==
477

edits