diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2021-10-11 11:09:32 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2021-10-11 11:09:32 +0200 |
| commit | 5b0ec6d87fe33649117cde1fb7fee1ad2652a88c (patch) | |
| tree | 435f26636702e4205fedcbe46458aad0a8b71e66 | |
| parent | 7f103dc8430b8194e2d5d96c5d675a9d9fff20f2 (diff) | |
| download | perlweeklychallenge-club-5b0ec6d87fe33649117cde1fb7fee1ad2652a88c.tar.gz perlweeklychallenge-club-5b0ec6d87fe33649117cde1fb7fee1ad2652a88c.tar.bz2 perlweeklychallenge-club-5b0ec6d87fe33649117cde1fb7fee1ad2652a88c.zip | |
First task done
| -rw-r--r-- | challenge-133/luca-ferrari/raku/ch-1.p6 | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/challenge-133/luca-ferrari/raku/ch-1.p6 b/challenge-133/luca-ferrari/raku/ch-1.p6 index 0f7a2ce5c4..87d0da2be5 100644 --- a/challenge-133/luca-ferrari/raku/ch-1.p6 +++ b/challenge-133/luca-ferrari/raku/ch-1.p6 @@ -1,18 +1,20 @@ #!raku -sub MAIN( Int $n where { $n > 0 } ) { - $n.say and exit if $n == 1; - - my Int $current-solution = $n +> 1; # divide by two - my Int $next-solution = 0; - while ( $next-solution < $current-solution ) { - $next-solution = ( $current-solution + $n / $current-solution ) +> 1 if ! $next-solution; - ( $current-solution, $next-solution ) = $next-solution, - ( $next-solution + $n / $next-solution ) +> 1; - +sub MAIN( Int $limit where { $limit > 0 } = 5 ) { + my @digits = 1 .. 9; + @digits.push: 0; + my $start = @digits.join; + + my @pandigital = lazy gather { + for $start ..^ Inf -> $current { + next if $start ~~ / ^0+ /; + my $found = 0; + $found += $current.comb.grep( $_ ).so ?? 1 !! 0 for @digits; + take $current if $found == @digits.elems; + } } - $current-solution.say; + @pandigital[ $_ ].say for 0 ..^ $limit; } |
