35 lines
898 B
Text
35 lines
898 B
Text
{def cache
|
|
{def cache.F {#.new}}
|
|
{def cache.M {#.new}}
|
|
{lambda {:f :n}
|
|
{let { {:f :f} {:n :n}
|
|
{:cx {if {equal? :f MF}
|
|
then {cache.F}
|
|
else {cache.M}}}
|
|
} {if {equal? {#.get :cx :n} undefined}
|
|
then {#.get {#.set! :cx :n {:f :n}} :n}
|
|
else {#.get :cx :n}}}}}
|
|
-> cache
|
|
|
|
{def MF
|
|
{lambda {:n}
|
|
{if {= :n 0}
|
|
then 1
|
|
else {- :n {MM {cache MF {- :n 1}}}}}}}
|
|
-> MF
|
|
|
|
{def MM
|
|
{lambda {:n}
|
|
{if {= :n 0}
|
|
then 0
|
|
else {- :n {MF {cache MM {- :n 1}}}}}}}
|
|
-> MM
|
|
|
|
{MF 80}
|
|
-> 50 (requires 55 ms)
|
|
|
|
{map MF {serie 0 100}} (requires75ms)
|
|
-> 1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9 10 11 11 12 13 13 14 14 15 16 16 17 17
|
|
18 19 19 20 21 21 22 22 23 24 24 25 25 26 27 27 28 29 29 30 30 31 32 32
|
|
33 34 34 35 35 36 37 37 38 38 39 40 40 41 42 42 43 43 44 45 45 46 46 47
|
|
48 48 49 50 50 51 51 52 53 53 54 55 55 56 56 57 58 58 59 59 60 61 61 62
|