From 5b0ec6d87fe33649117cde1fb7fee1ad2652a88c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 Oct 2021 11:09:32 +0200 Subject: First task done --- challenge-133/luca-ferrari/raku/ch-1.p6 | 24 +++++++++++++----------- 1 file 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; } -- cgit