diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-04-07 09:22:12 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-04-07 09:22:12 +0100 |
| commit | 987bc609faf9e2478e0c84aef7e51255f1c84b7c (patch) | |
| tree | 1570825d86faa4bb3743689ab1b30e7769d9d230 | |
| parent | 061e09dfcd612ddb9be4ad3f5e36c46d73d03a39 (diff) | |
| download | perlweeklychallenge-club-987bc609faf9e2478e0c84aef7e51255f1c84b7c.tar.gz perlweeklychallenge-club-987bc609faf9e2478e0c84aef7e51255f1c84b7c.tar.bz2 perlweeklychallenge-club-987bc609faf9e2478e0c84aef7e51255f1c84b7c.zip | |
Much better way of doing unique permutations
| -rw-r--r-- | challenge-055/simon-proctor/raku/ch-2.p6 | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/challenge-055/simon-proctor/raku/ch-2.p6 b/challenge-055/simon-proctor/raku/ch-2.p6 index aee75ea167..40d1f60451 100644 --- a/challenge-055/simon-proctor/raku/ch-2.p6 +++ b/challenge-055/simon-proctor/raku/ch-2.p6 @@ -17,16 +17,7 @@ multi sub MAIN( *@input where { $_.elems >= 2 && $_.all ~~ Int } ) { } sub unique-perms ( @input ) { - my %seen; - my @perms = @input.permutations; - gather { - while ( @perms ) { - my $next = @perms.shift; - next if %seen{$next}:exists; - %seen{$next} = True; - take $next; - } - } + @input.permutations.unique(:as(*.join(","))); } multi sub is-wave( 'lte', Int $a, Int $b where { $a <= $b } ) { True } |
