Skip to content

Instantly share code, notes, and snippets.

@tafsiri
Created January 15, 2011 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tafsiri/780714 to your computer and use it in GitHub Desktop.
Save tafsiri/780714 to your computer and use it in GitHub Desktop.
#get rid of the object and just use a method as a container
fibmemoclosure := method(num,
memo := Map clone
fibmemo := block(num, #note 'blocks' are lexically scoped
memo atPut(0 asString, 0)
memo atPut(1 asString, 1)
fibhelp := method(num,
one := memo at((num-1) asString)
two := memo at((num-2) asString)
if(one == nil
, one = fibhelp(num-1,memo)
memo atPut((num-1) asString, one)
)
if(two == nil
, two = fibhelp(num-2,memo)
memo atPut((num-2) asString, two)
)
one + two
)
fibhelp(num,memo)
)
return fibmemo
) call setIsActivatable(true)
fibmemoclosure(12) println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment