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
"""

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
"""

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.1.tar.gz (2.9 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.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: show_recursion_tree-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 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.1.tar.gz
Algorithm Hash digest
SHA256 753000fb10eba85b4d837cda1f675c3a52e63077462276c3e38eaef98184c17c
MD5 5b1bab8bbcb49795ff065c6f5d4a2555
BLAKE2b-256 49761dc394c7423764b065a9522a36aa7ab2f5a59b6906d17ba628279889022e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for show_recursion_tree-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfc0e30f4682cef6cad53058df577872bf374975316ec0b4264db2f85486db8e
MD5 ba1095d672b56d462daf134b6226db2c
BLAKE2b-256 6b1527c5426c395596356c05627497380adc1307352365b2acba4f85caaa8776

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