aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2020-03-16 08:53:01 +0100
committerLuca Ferrari <fluca1978@gmail.com>2020-03-16 11:00:35 +0100
commitb3472c66c6546f3373094f47c7889fa33cbc7b1b (patch)
tree00193333187fa966ce155709cfb3fb94631dcfb6
parent0f685e69ee3456d0c9fdc072a626eb4cc466b4eb (diff)
downloadperlweeklychallenge-club-b3472c66c6546f3373094f47c7889fa33cbc7b1b.tar.gz
perlweeklychallenge-club-b3472c66c6546f3373094f47c7889fa33cbc7b1b.tar.bz2
perlweeklychallenge-club-b3472c66c6546f3373094f47c7889fa33cbc7b1b.zip
Task1 done.
-rw-r--r--challenge-052/luca-ferrari/raku/ch-1.p645
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-052/luca-ferrari/raku/ch-1.p6 b/challenge-052/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..5662de8d30
--- /dev/null
+++ b/challenge-052/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,45 @@
+#!env raku
+#
+#
+# Task 1
+# <https://perlweeklychallenge.org/blog/perl-weekly-challenge-052/>
+#
+# Write a script to accept two numbers between 100 and 999.
+# It should then print all Stepping Numbers between them.
+#
+# A number is called a stepping number if the adjacent digits
+# have a difference of 1.
+# For example, 456 is a stepping number but 129 is not.
+
+
+
+
+
+sub MAIN( Int:D :$from where { 100 <= $from <= 999 },
+ Int:D :$to where { 100 <= $to <= 999 && $to > $from } ) {
+
+ say "Searching STEPPING NUMBERs between $from and $to";
+
+
+ # compose manually all possible stepping numbers
+ # starting from the hundred value of the from number
+ my ( $h, $d, $u ) = $from.comb;
+ my ( $H, $D, $U ) = $to.comb;
+ my @stepping = ();
+ while ( $h <= $H ) {
+
+ for 1, -1 {
+ my $dd = ( 0 <= $h + $_ <= 9 ) ?? $h + $_ !! Nil;
+ for 1, -1 {
+ my $uu = ( 0 <= $dd + $_ <= 9 ) ?? $dd + $_ !! Nil;
+
+ @stepping.push( $h * 100 + $dd * 10 + $uu ) if ( $uu && $dd );
+ }
+ }
+
+ $h++;
+ }
+
+ say @stepping.grep( $from <= * <= $to ).join( "\n" );
+ say "-----------------------";
+}