RosettaCodeData/Task/Count-the-coins/Icon/count-the-coins-2.icon
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

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