Skip to content

Instantly share code, notes, and snippets.

@holli-holzer
Last active May 17, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holli-holzer/8a69c6ea46782873ec21d02c8785026e to your computer and use it in GitHub Desktop.
Save holli-holzer/8a69c6ea46782873ec21d02c8785026e to your computer and use it in GitHub Desktop.
my $tree = {
v => 1,
l => {
v => 2,
l => {
v => 4,
r => { v => 7 },
},
r => {
v => 3,
l => { v => 5 },
r => { v => 6 },
}
},
};
sub walk($hash, &block)
{
$hash.█
.&walk(&block) for grep *.so, $hash<l>, $hash<r>;
}
my $sum = sum gather $tree.&walk({ take .<v> });
$tree.&walk({ .<v> = $sum - .<v> });
dd $tree;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment