diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-04-19 14:34:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-19 14:34:16 +0100 |
| commit | fb33808c1389814123e52462f5e62fbb8ac7e332 (patch) | |
| tree | 575d807cd2efa267c7cc5a614f7072a1b15928ff | |
| parent | c802056581d745658579f53122baa0fbd121f306 (diff) | |
| parent | 1442d6fb923d1e7b01cdb8671cf3e7b9896cb19f (diff) | |
| download | perlweeklychallenge-club-fb33808c1389814123e52462f5e62fbb8ac7e332.tar.gz perlweeklychallenge-club-fb33808c1389814123e52462f5e62fbb8ac7e332.tar.bz2 perlweeklychallenge-club-fb33808c1389814123e52462f5e62fbb8ac7e332.zip | |
Merge pull request #1593 from holli-holzer/master
more multi
| -rw-r--r-- | challenge-056/markus-holzer/raku/ch-1.p6 | 15 | ||||
| -rw-r--r-- | challenge-056/markus-holzer/raku/ch-2.p6 | 25 |
2 files changed, 10 insertions, 30 deletions
diff --git a/challenge-056/markus-holzer/raku/ch-1.p6 b/challenge-056/markus-holzer/raku/ch-1.p6 index 43e9525eb0..e9c3c4f06d 100644 --- a/challenge-056/markus-holzer/raku/ch-1.p6 +++ b/challenge-056/markus-holzer/raku/ch-1.p6 @@ -1,19 +1,10 @@ -sub USAGE() { - print Q:c:to/EOH/; - ch-2.p6 <k> <N1> <N2> <N3> ... <Nn> - - Example: - ch-1.p6 2 2 4 6 7 9 - EOH -} - -sub MAIN( UInt $k, *@N where *.elems > 1 ) +sub MAIN( UInt $k, *@N ) { - CATCH { USAGE() and exit -1; } + CATCH { say $*USAGE() and exit -1; } .say for ( @N>>.UInt ) .pairs - .combinations( 2 ) + .rotor( 2 => -1 ) .grep({ .[1].value - .[0].value == $k }) .map( *>>.key ); } diff --git a/challenge-056/markus-holzer/raku/ch-2.p6 b/challenge-056/markus-holzer/raku/ch-2.p6 index 513a6d29ac..2665eb2125 100644 --- a/challenge-056/markus-holzer/raku/ch-2.p6 +++ b/challenge-056/markus-holzer/raku/ch-2.p6 @@ -20,23 +20,12 @@ my %tree = .join('→').say for find-path-sum( %tree, 22 ); -multi sub find-path-sum( %tree, $n ) -{ - gather find-path-sum( %tree, $n, [] ); -} +multi sub find-path-sum( Hash:D $tree, Int $n ) { + gather find-path-sum( $tree, $n, [] ); } -multi sub find-path-sum( $tree, $n, $path ) -{ - for $tree.keys -> $k - { - my $p = $path.clone.push( $k ); +multi sub find-path-sum( Hash:D $tree, Int $n, Array $path ) { + find-path-sum( $tree{ $_ }, $n, $path.clone.push($_) ) + for $tree.keys; } - if my $t = $tree{ $k } - { - find-path-sum( $t, $n, $p ); - next; - } - - take $p if $p.sum == $n; - } -}
\ No newline at end of file +multi sub find-path-sum( Any, Int $n, Array $path ) { + take $path if $path.sum == $n; }
\ No newline at end of file |
