Home › Forums › kdb+ › How to walkthrough a tree and calculate value on path? › Re: How to walkthrough a tree and calculate value on path?
-
This is my solution
tree:([]parent:`A`A`A`B`B`E`E;child:`B`C`D`E`F`G`H;data:1 2 3 4 5 6 7); getVal:{?[`tree;((=;`parent;enlist x);(=;`child;enlist y));();`data]} checkParent:{first ?[`tree;enlist (=;`child;enlist x);();`parent]} getPathVal:{[x;y] $[x~checkParent[y];getVal[x;y];getVal[checkParent[y];y]*.z.s[x;checkParent[y]]]}