Count the coins: Difference between revisions

(Added EchoLisp)
(→‎{{header|UNIX Shell}}: Add V7 version)
Line 2,020:
count_change 100 25 10 5 1
# (optional task exceeds a subscript limit in ksh88)</lang>
 
And just for fun, here's one that works even with the original V7 shell:
 
{{works with|sh|v7}}
<lang bash>if [ $# -lt 2 ]; then
set ${1-100} 25 10 5 1
fi
amount=$1
shift
ways_0=1
for coin in "$@"; do
j=$coin
while [ $j -le $amount ]; do
d=`expr $j - $coin`
eval "ways_$j=\`expr \${ways_$j-0} + \${ways_$d-0}\`"
j=`expr $j + 1`
done
done
eval "echo \$ways_$amount"</pre>
 
{{Out}}
1,480

edits