Using recursion, is it possible to set the initial input as a fixed letter so that it will not be affected as the process loops?
<p>Implement the function tree that takes a number of slices n and a rune as arguments, and generates a stack of runes (shape) scaled and overlayed on top of each other.</p>

<p>the shape at the top must be 1/n the size of the original shape. the shape at the second level must be 2/n the size of the original shape and so on. i.e. the shape at the bottom is the original shape.</p>

<p>So I tried to do this in a recursive manner using some ideas from mathematical induction.</p>

<pre><code>def tree(n, shape):
    a = n
    if n == 1:
        return scale(1/a, shape)
    else:
        return overlay_frac((n-1)/n, tree(n-1, shape) , scale(n/a, shape))
</code></pre>

<p>My question is how would you fix the initial value of <code>n</code> because this recursion keeps altering the value? I can't set <code>a = n</code> outside of the recursion as <code>n</code> is defined in the function.</p>

<p>Is there a way for me to set the initial value of <code>n</code> to another letter so it wouldn't change?</p>

<p>Right now I'm not even sure if this code works. But without being able to fix it, I can't test it.</p>

<p>FYI: I am aware that you guys might not know what <code>overlay_frac</code> and <code>scale</code> does but the codes for those are given to me.</p>

<p>My question really revolves around a way to set the initial input of a recursion so that it will not be affected as the process loops.</p>

<p>Adding another parameter is certainly a feasible option. In the event that you under certain constraints and unable to change the formal parameters defined for the outer function, you may consider using a helper function as well.</p>

<pre><code>function tree(n, rune){
    function drawTree(i) {
        if (i === 1) {
            return rune;
        } else {
            return overlay_frac(1 / k, scale((1 + n - i)/ n, rune),
                drawTree(i - 1));
        }
    }
    return drawTree(n);
}
</code></pre>

python