19 lines
418 B
Text
19 lines
418 B
Text
procedure CountCoins(amt,coins) # very slow, recurse by coin value
|
|
local count
|
|
static S
|
|
|
|
if type(coins) == "list" then {
|
|
S := sort(set(coins))
|
|
if *S < 1 then runerr(205,coins)
|
|
return CountCoins(amt)
|
|
}
|
|
else {
|
|
/coins := 1
|
|
if value := S[coins] then {
|
|
every (count := 0) +:= CountCoins(amt - (0 to amt by value), coins + 1)
|
|
return count
|
|
}
|
|
else
|
|
return (amt ~= 0) | 1
|
|
}
|
|
end
|