File tree Expand file tree Collapse file tree 5 files changed +38
-3
lines changed Expand file tree Collapse file tree 5 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 11# Recursion Visualiser
2- Recursion visualiser is a python tool that draws recursion tree for recursive function with very less code changes.
2+ Recursion visualiser is a python tool that visualizes recursion tree with animation and draws recursion tree for recursive function.
3+ It works with almost any type of recursive function.
4+ Just add the recursion-visualiser decorator to your function and let it do the rest of the work.
5+
36
47 ## Installation
58The only dependency for recursion visualiser is Graphviz which you can download from [ here] ( https://www.graphviz.org/download/ )
@@ -84,6 +87,9 @@ This is taken from one of my answers on quora where I had to manually draw recu
8487 - [x] Minimal working version
8588 - [x] Upload package to pypi
8689 - [x] Support animation
90+ - [ ] Support aliasing for function name
91+ - [ ] Show repeated states
92+ - [ ] Support node_color, backgroundcolor etc
8793 - [ ] Refactor
8894 - [ ] Handle base cases
8995 - [ ] Make more beautiful trees
Original file line number Diff line number Diff line change 1+ # Author: Bishal Sarang
2+ from visualiser .visualiser import Visualiser as vs
3+
4+ """
5+ Number of ways to make change:
6+ """
7+ @vs (ignore_args = ["coins" ], show_argument_name = False )
8+ def f (coins , amount , n ):
9+ if amount == 0 :
10+ return 1
11+
12+ if amount < 0 :
13+ return 0
14+
15+ if n <= 0 and amount >= 1 :
16+ return 0
17+
18+ include = f (coins = coins , amount = amount - coins [n - 1 ], n = n )
19+ exclude = f (coins = coins , amount = amount , n = n - 1 )
20+
21+ return include + exclude
22+
23+ def main ():
24+ amount = 5
25+ coins = [1 , 2 , 5 ]
26+ print (f (coins = coins , amount = amount , n = len (coins )))
27+ vs .make_animation ("coin_change.gif" , delay = 3 )
28+
29+ if __name__ == "__main__" :
30+ main ()
Original file line number Diff line number Diff line change @@ -36,5 +36,4 @@ def f(sum, ans):
3636
3737# Call solve with sum and an empty list
3838f (sum = sum , ans = [])
39- # Save recursion tree to a file
40- vs .make_animation ("make.gif" , delay = 2 )
39+ vs .write_image ("make_sum.png" )
You can’t perform that action at this time.
0 commit comments