Revision 855,
868 bytes
checked in by mmckerns, 5 months ago
(diff) |
updated copyright to 2016
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # Author: Mike McKerns (mmckerns @caltech and @uqfoundation) |
---|
4 | # Copyright (c) 2012-2016 California Institute of Technology. |
---|
5 | # License: 3-clause BSD. The full license text is available at: |
---|
6 | # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE |
---|
7 | |
---|
8 | #from mystic.cache import inf_cache as memoized |
---|
9 | #from klepto.safe import inf_cache as memoized |
---|
10 | from memoize import memoize as memoized |
---|
11 | |
---|
12 | from klepto.archives import file_archive |
---|
13 | from timer import timed |
---|
14 | |
---|
15 | # here caching saves time in a recursive function... |
---|
16 | @memoized() |
---|
17 | @timed() |
---|
18 | def fibonacci(n): |
---|
19 | "Return the nth fibonacci number." |
---|
20 | if n in (0, 1): |
---|
21 | return n |
---|
22 | print 'calculating %s' % n |
---|
23 | return fibonacci(n-1) + fibonacci(n-2) |
---|
24 | |
---|
25 | fibonacci.archive(file_archive('fibonacci.pkl')) |
---|
26 | fibonacci.load() |
---|
27 | |
---|
28 | print fibonacci(7) |
---|
29 | print fibonacci(9) |
---|
30 | |
---|
31 | fibonacci.dump() |
---|
32 | |
---|
33 | |
---|
34 | # EOF |
---|
Note: See
TracBrowser
for help on using the repository browser.