aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-13 10:52:17 +0100
committerGitHub <noreply@github.com>2020-07-13 10:52:17 +0100
commit81128760a47df4e2fe2f157af41409f6926dee61 (patch)
tree9abb7e6bcb45570d513949443182054db6f1d84f
parent6f7a82d3ccceb9b0ca70e6ee60863afe79907dc5 (diff)
parent01a69006d8e88e6d5f402deb2620a261af34c155 (diff)
downloadperlweeklychallenge-club-81128760a47df4e2fe2f157af41409f6926dee61.tar.gz
perlweeklychallenge-club-81128760a47df4e2fe2f157af41409f6926dee61.tar.bz2
perlweeklychallenge-club-81128760a47df4e2fe2f157af41409f6926dee61.zip
Merge pull request #1938 from fluca1978/pwc69
Pwc69
-rw-r--r--challenge-069/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-069/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-069/luca-ferrari/raku/ch-1.p650
-rw-r--r--challenge-069/luca-ferrari/raku/ch-2.p631
4 files changed, 83 insertions, 0 deletions
diff --git a/challenge-069/luca-ferrari/blog-1.txt b/challenge-069/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..7eecad9c00
--- /dev/null
+++ b/challenge-069/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/07/13/PerlWeeklyChallenge69.html#task1
diff --git a/challenge-069/luca-ferrari/blog-2.txt b/challenge-069/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..27ef7197c5
--- /dev/null
+++ b/challenge-069/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/07/13/PerlWeeklyChallenge69.html#task2
diff --git a/challenge-069/luca-ferrari/raku/ch-1.p6 b/challenge-069/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..018e9ce2e0
--- /dev/null
+++ b/challenge-069/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,50 @@
+#!raku
+
+
+
+
+
+sub MAIN( Int $A where { 1 <= $A <= 10**15 } = 1
+ , Int $B where { $A <= $B <= 10**15 } = 10**15 ) {
+ say "Working from $A to $B";
+
+ my %reverse = 0 => 0
+ , 1 => 1
+ , 6 => 9
+ , 8 => 8
+ , 9 => 6;
+
+
+ my @found = gather {
+ for $A .. $B {
+ # special case: single number
+ take $_ if $_.chars == 1 && $_ == any( 0, 1, 8 );
+
+ my @digits = $_.split: '', :skip-empty;
+
+ # special case: if the number of digits is odd
+ # the central digit must be a self reversing one
+ next if ! @digits.elems %% 2
+ && @digits[ ( @digits.elems / 2 ).Int ] != any ( 0, 1 , 8 );
+
+ my $ok = True;
+ CHECKING:
+ for 0 ..^ @digits.elems -> $index {
+ my ( $left, $right ) = $index, @digits.elems - $index - 1;
+ last if $left == $right || $left > $right;
+ $ok = False if ( %reverse{ @digits[ $left ] }:!exists )
+ || ( %reverse{ @digits[ $right ] }:!exists );
+
+ last CHECKING if ! $ok;
+ $ok &= %reverse{ @digits[ $left ] } == @digits[ $right ];
+ last CHECKING if ! $ok;
+ }
+
+ take $_ if $ok;
+ }
+ } # end of gather
+
+
+ @found.unique.join( ', ' ).say;
+
+}
diff --git a/challenge-069/luca-ferrari/raku/ch-2.p6 b/challenge-069/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..4603520f6f
--- /dev/null
+++ b/challenge-069/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,31 @@
+#!raku
+
+
+
+sub switch( Str $string where { $string ~~ / ^ <[0 1]>+ $ / } ) {
+ my @bits;
+ for $string.split( '', :skip-empty ) {
+ @bits.push( 0 ) && next if $_ == 1;
+ @bits.push: 1 if $_ == 0;
+ }
+
+ @bits.join;
+}
+
+
+sub reverse( Str $string where { $string ~~ / ^ <[0 1]>+ $ / } ) {
+ $string.split( '', :skip-empty ).reverse.join;
+}
+
+sub MAIN( Int:D $max? = 100 ) {
+ my $current-string;
+ for 0 .. $max {
+ $current-string = '' if $_ == 0;
+ $current-string = '0' if $_ == 1;
+ next if $_ <= 1;
+ $current-string = $current-string ~ '0' ~ switch( reverse( $current-string ) );
+ }
+
+ $current-string.csay;
+
+}