Skip to content

va1ha11a/rjk_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rjk Tools

Misc tools to help with programming more efficently

decorators

Example of the dynamic_programming usage on a fibonacci function

from rjk_tools.decorators import dynamic_programming

@dynamic_programming
def fib(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)	

Example of results:

>>>fib(8)
>>>21

Without the decorator the following functioncalls would be made:

fib(8),fib(7),fib(6),fib(5),fib(4),fib(3),fib(2),fib(1),fib(0),fib(1),fib(2),fib(1),fib(0),fib(3),fib(2),fib(1),fib(0),fib(1),fib(4),fib(3),fib(2),fib(1),fib(0),fib(1),fib(2),fib(1),fib(0),fib(5),fib(4),fib(3),fib(2),fib(1),fib(0),fib(1),fib(2),fib(1),fib(0),fib(3),fib(2),fib(1),fib(0),fib(1),fib(6),fib(5),fib(4),fib(3),fib(2),fib(1),fib(0),fib(1),fib(2),fib(1),fib(0),fib(3),fib(2),fib(1),fib(0),fib(1),fib(4),fib(3),fib(2),fib(1),fib(0),fib(1),fib(2),fib(1),fib(0)

With the decorator it is reduced to:

fib(8),fib(7),fib(6),fib(5),fib(4),fib(3),fib(2),fib(1),fib(0)

Subsequent runs only run previously unrun calls.

>>>fib(9)
>>>34

The above only will run:

fib(9)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages