I would like to know how to get the total height of a binary tree.
This is how far I came before I started to error loop in my head.
height( leaf(_), 1 ).
height( branch(Branch1, Branch2), H ):-
height(Branch1, H1),
height(Branch2, H2),
is max(H1, H2).
I think I’m on the right track but I can’t seem to wrap my head around this last part (since those variables can’t be changed once a value has been set).
Well, you’re almost there. I don’t see much to say since what you wrote already is pretty correct, so I’ll just finish the job.