Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, lefts give this a stab.</p> <p>I would go about it like this with some pseudo code</p> <pre><code>foreach leaf in knownLeafs parent = leaf.parent //get the leaf parent parent.total = parent.total + leaf.value //add leaf value to parent total while parent.parent != null //loop until no more parents, this would be the root { current = parent parent = parent.parent //move up the structure parent.total = parent.total + current.total } next leaf </code></pre> <p>you would need to create a function that will, given a node, return the parent node</p> <p>node GetParentNodeFrom(node)</p> <p>the new pseudo code would look something like this</p> <pre><code>foreach leaf in knownLeafs parent = GetParentNodeFrom(leaf) //get the leaf parent parent.total = parent.total + leaf.value //add leaf value to parent total while GetParentNodeFrom(parent) != null //loop until no more parents, this would be the root { current = parent parent = GetParentNodeFrom(current) //move up the structure parent.total = parent.total + current.total } next leaf </code></pre> <p>Sorry, my mistake, you should only move the leaf value up, not the totals too. See new leafValue used.</p> <pre><code>foreach leaf in knownLeafs parent = GetParentNodeFrom(leaf) //get the leaf parent leafValue = leaf.value parent.total = parent.total + leafValue //add leaf value to parent total while GetParentNodeFrom(parent) != null //loop until no more parents, this would be the root { current = parent parent = GetParentNodeFrom(current) //move up the structure parent.total = parent.total + leafValue } next leaf </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload