diff options
| author | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-04-19 20:18:44 +0200 |
|---|---|---|
| committer | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-04-19 20:18:44 +0200 |
| commit | ad1e900f5912803c17c47b0484d7c9849dedf115 (patch) | |
| tree | c2ce6df4afb4231f76dfc24dde9ff8cdfb0e1458 /challenge-056 | |
| parent | 1442d6fb923d1e7b01cdb8671cf3e7b9896cb19f (diff) | |
| download | perlweeklychallenge-club-ad1e900f5912803c17c47b0484d7c9849dedf115.tar.gz perlweeklychallenge-club-ad1e900f5912803c17c47b0484d7c9849dedf115.tar.bz2 perlweeklychallenge-club-ad1e900f5912803c17c47b0484d7c9849dedf115.zip | |
better scoping
Diffstat (limited to 'challenge-056')
| -rw-r--r-- | challenge-056/markus-holzer/raku/ch-2.p6 | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/challenge-056/markus-holzer/raku/ch-2.p6 b/challenge-056/markus-holzer/raku/ch-2.p6 index 2665eb2125..2f2c0dad0b 100644 --- a/challenge-056/markus-holzer/raku/ch-2.p6 +++ b/challenge-056/markus-holzer/raku/ch-2.p6 @@ -20,12 +20,14 @@ my %tree = .join('→').say for find-path-sum( %tree, 22 ); -multi sub find-path-sum( Hash:D $tree, Int $n ) { - gather find-path-sum( $tree, $n, [] ); } +multi sub find-path-sum( Hash:D $tree, Int $n ) +{ + multi sub find-path-sum( Hash:D $tree, Int $n, Array $path ) { + find-path-sum( $tree{ $_ }, $n - $_, $path.clone.push($_) ) + for $tree.keys; } -multi sub find-path-sum( Hash:D $tree, Int $n, Array $path ) { - find-path-sum( $tree{ $_ }, $n, $path.clone.push($_) ) - for $tree.keys; } + multi sub find-path-sum( Any, Int $n, Array $path ) { + take $path if $n == 0; } -multi sub find-path-sum( Any, Int $n, Array $path ) { - take $path if $path.sum == $n; }
\ No newline at end of file + gather find-path-sum( $tree, $n, [] ); +}
\ No newline at end of file |
