Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,13 @@
function count_change {
local -i amount=$1 coin j
local ways=(1)
shift
for coin; do
for (( j=coin; j <= amount; j++ )); do
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
done
done
echo "${ways[amount]}"
}
count_change 100 25 10 5 1
count_change 100000 100 50 25 10 5 1

View file

@ -0,0 +1,14 @@
function count_change {
typeset -i amount=$1 coin j
typeset ways
set -A ways 1
shift
for coin; do
for (( j=coin; j <= amount; j++ )); do
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
done
done
echo "${ways[amount]}"
}
count_change 100 25 10 5 1
count_change 100000 100 50 25 10 5 1

View file

@ -0,0 +1,16 @@
function count_change {
typeset -i amount=$1 coin j
typeset ways
set -A ways 1
shift
for coin; do
let j=coin
while (( j <= amount )); do
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
let j+=1
done
done
echo "${ways[amount]}"
}
count_change 100 25 10 5 1
# (optional task exceeds a subscript limit in ksh88)

View file

@ -0,0 +1,15 @@
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"