Skip to main content

print recursion trees in terminal

Project description

show_recursion_tree

prints out recursion tree

Installation

pip install show_recursion_tree

Example 1

@show_recursion_tree
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

print(factorial(5))

"""
  5:120 
    |
  4:24
   |
 3:6
  |
 2:2
  |
1:1

120
"""

Example 2

from show_recursion_tree import show_recursion_tree

@show_recursion_tree
def fib(n):
    if n == 1:
        return 1
    if n == 2:
        return 1
    
    return fib(n-2) + fib(n-1)

print(fib(5))
"""
      _________5:5__________
      |                    |
  ___3:2_____         ___4:3________
  |         |         |            |
1:1       2:1       2:1        ___3:2_____
                               |         |
                             1:1       2:1

5
"""

Example 3

@show_recursion_tree
def f(n):
    if n <= 4:
        return 1
    
    return f(n-4) + f(n-3) + f(n-2) + f(n-1)

f(7)

"""
  ___________________7:13______________________
  |    |             |                        |
3:1  4:1    ________5:4_________    ________6:7________________
            |    |        |    |    |    |      |             |
          1:1  2:1      3:1  4:1  2:1  3:1    4:1    ________5:4_________
                                                     |    |        |    |
                                                   1:1  2:1      3:1  4:1
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

show_recursion_tree-0.0.4.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

show_recursion_tree-0.0.4-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file show_recursion_tree-0.0.4.tar.gz.

File metadata

  • Download URL: show_recursion_tree-0.0.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for show_recursion_tree-0.0.4.tar.gz
Algorithm Hash digest
SHA256 eb40dbef6892dcc76a751bb2cbe4772a1af3734e4810b6022e1ffbfd489f71ee
MD5 e80925e1088bcb15075b0a74f659d7ab
BLAKE2b-256 07eed7f951953c7b868fa79de4a5f5d8551199b593296c9d2eba7f553f258954

See more details on using hashes here.

File details

Details for the file show_recursion_tree-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for show_recursion_tree-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 03c9ef6d984b313789d01dafbf2c832d50760d4bc5ee8df7c4170b142e03702c
MD5 f6160abb604d0e2374325451ee45fb0f
BLAKE2b-256 87394f8a52bccc7b49d82d150782e2bab03b3b5bba3ac041fc3b6365ed529345

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page