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.3.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.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: show_recursion_tree-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 cdf7627358b409da6565227b5ae519c42f80c13134bfddc272a7570955880963
MD5 839c4a2c01033801aed4a2a7ccc98edb
BLAKE2b-256 09ba5493d542239307605fa6a652999031b9cb8db873839059f5d560e0183a35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for show_recursion_tree-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e887f3b070b740d15b453294af0d3008668473a57ff8261ee2fa0a7e73aa7b07
MD5 592189c5f73e03fb4788b977a499acaa
BLAKE2b-256 e2fc719c28f300041b3ae9fa754021f4aa099ef3bb3c7b81ebb6b3410a4f9102

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