Count the coins: Difference between revisions
Content added Content deleted
Line 1,202: | Line 1,202: | ||
len cache[] 100000 * 7 + 6 |
len cache[] 100000 * 7 + 6 |
||
val[] = [ 1 5 10 25 50 100 ] |
val[] = [ 1 5 10 25 50 100 ] |
||
proc |
proc count sum kind . r . |
||
if sum = 0 |
if sum = 0 |
||
r = 1 |
r = 1 |
||
elif sum < 0 or kind = 0 |
elif sum < 0 or kind = 0 |
||
r = 0 |
r = 0 |
||
elif cache[sum * 7 + kind] > 0 |
|||
⚫ | |||
else |
else |
||
chind = sum * 7 + kind |
|||
if cache[chind] = 0 |
|||
call count sum - val[kind] kind r2 |
|||
call count sum kind - 1 r1 |
|||
cache[chind] = r1 + r2 |
|||
. |
|||
⚫ | |||
. |
. |
||
. |
. |
||
call |
call count 100 4 r |
||
print r |
print r |
||
call |
call count 10000 6 r |
||
print r |
print r</syntaxhighlight> |
||
</syntaxhighlight> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |