aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2023-05-02 10:49:12 +0200
committerLuca Ferrari <fluca1978@gmail.com>2023-05-02 10:49:12 +0200
commit83bd69b92aeb695617190c4a9325c0b9134b42fa (patch)
tree0f585e7d149ff8515e9987acbf16613aeb9653e9
parent3f928391e6f2ec77a88d2bf5109e196712f958ab (diff)
downloadperlweeklychallenge-club-83bd69b92aeb695617190c4a9325c0b9134b42fa.tar.gz
perlweeklychallenge-club-83bd69b92aeb695617190c4a9325c0b9134b42fa.tar.bz2
perlweeklychallenge-club-83bd69b92aeb695617190c4a9325c0b9134b42fa.zip
Task 2 done
-rw-r--r--challenge-215/luca-ferrari/raku/ch-2.p629
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;
+}