Mystery is an handy tool designed for analyzing and generating International Baccalaureate (IB) format traces through automatic recursion parsing. This tool is ideal for educators, students, and programmers who work with recursive functions and need a structured way to trace and analyze their behavior.
- Python 3.7 or higher
pip3 install astor
Start by importing the necessary functions from the analyzer module:
from analyzer import analyze, trace
Define a list to keep track of the recursion stack:
stack = []
Write your recursive function. Use the @trace
decorator to enable tracing:
@trace(stack)
def mystery(x):
if x > 0:
return mystery(x-1) * x
else:
return 1
Call your function with desired parameters and analyze the trace:
mystery(5)
analyze(mystery, stack) # This will print and return the result in list format
mystery(5)
= mystery(4) * 5
= mystery(3) * 4 * 5
= mystery(2) * 3 * 4 * 5
= mystery(1) * 2 * 3 * 4 * 5
= mystery(0) * 1 * 2 * 3 * 4 * 5
= 1 * 1 * 2 * 3 * 4 * 5
= 120