Here is the "on demand" cache version I spoke of.
Note it runs slower (because it should).
Again it depends on your applications bevahvior as to its worth.
It would payoff if the factorials needed were sparse (but still
repeatedly used [multiple hits in the cache]).
If I made FACT any slower Erich's post might start to payoff :-)
to do
make "start timemilli
invalidate_fact_cache
for[num 100 999][
if equalp :num(sum fact item 1 :num
fact item 2 :num
fact item 3 :num)
[pr :num]]
show (timemilli - :start) / 600
end
to fact :n
if (item :n :factarr) = -1 [setitem :n :factarr fact_real :n]
op item :n :factarr
end
to fact_real :n
op ifelse :n<2[1][:n*fact_real :n-1]
end
to invalidate_fact_cache
make "factarr(array 10 0)
for[i 0 9][
setitem :i :factarr -1]
end
do
145
3.54333333333333
--
===============================================================
George Mills
email: mills@softronix.com
http://www.softronix.com
The www page contains some very powerful educational software.
Our single most important investment is our kids.
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org. Mail
questions about the list administration to logofdn@gsn.org. To
unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home