diff options
| -rw-r--r-- | challenge-215/luca-ferrari/raku/ch-2.p6 | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-215/luca-ferrari/raku/ch-2.p6 b/challenge-215/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..0394342968 --- /dev/null +++ b/challenge-215/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,29 @@ +#!raku + +# +# Perl Weekly Challenge 215 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-215/> +# + +sub MAIN( :$count is copy where { $count >= 0 } , + *@digits is copy where { @digits.grep( 0 <= *.Int <= 1 ).elems == @digits.elems } ) { + + my $done = False; + while $count { + $done = False; + for 1 ..^ @digits.elems - 1 { + if ( @digits[ $_ ] == 0 && @digits[ $_ - 1 ] == 0 && @digits[ $_ + 1 ] == 0 ) { + @digits[ $_ ] = 1; + $count--; + $done = True; + } + } + + '0'.say and exit if ! $done; + } + + '1'.say and exit if ! $count; + '0'.say; +} |
