I have a recursive function with 2 indices of the form:
function calc_rs(n,p)
println("Calculating for ($n,$p)")
if n != 1
calc_rs(n-1, 1)
calc_rs(n-1, p+1)
end
end
It is called as:
calc_rs(N, 1)
then it recurses until it hits the base case with (1,p). For example, with N=3:
calc_rs(3, 1)
Calculating for (3,1)
Calculating for (2,1)
Calculating for (1,1)
Calculating for (1,2)
Calculating for (2,2)
Calculating for (1,1)
Calculating for (1,3)
I am trying to create a plot of this recursion. I have made this manually as:
using GraphRecipes, Plots
g = [0 1 1 0 0 0;
0 0 0 1 1 0;
0 1 0 1 0 1;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0]
names=["(3,1)", "(2,1)", "(2,2)", "(1,1)", "(1,2)", "(1,3)"]
p = palette(:rainbow, 3)
graphplot(g, names=names, curvature_scalar=0, fontsize=12, nodeweights=[3,2,2,1,1,1], markercolor = [p[1],p[2],p[2],p[3],p[3],p[3]])
Which results in what I expect:
Is there an easier way to do this using e.g. trees? It seems a little difficult to automate the process in this way, I just can’t wrap my head around it.