aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-069/rage311/perl5/ch-1.pl62
-rw-r--r--challenge-069/rage311/perl5/ch-2.pl47
2 files changed, 109 insertions, 0 deletions
diff --git a/challenge-069/rage311/perl5/ch-1.pl b/challenge-069/rage311/perl5/ch-1.pl
new file mode 100644
index 0000000000..e673591f2e
--- /dev/null
+++ b/challenge-069/rage311/perl5/ch-1.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/env perl
+
+use 5.032;
+use warnings;
+use feature 'signatures';
+no warnings 'experimental::signatures';
+
+use constant INVERTED => {
+ 0 => 0,
+ 1 => 1,
+ 8 => 8,
+ 6 => 9,
+ 9 => 6,
+};
+
+sub strobotize ($number) {
+ my @digits = split //, $_;
+ return () if grep { !exists INVERTED->{$_} } @digits;
+
+ my $odd_len = @digits % 2;
+ my $middle = $digits[int @digits / 2];
+ return () if $odd_len && $middle != 0 && $middle != 1 && $middle != 8;
+
+ for (0 .. $#digits) {
+ return () if $digits[$_] != INVERTED->{$digits[$#digits - $_]}
+ }
+
+ return $number;
+}
+
+sub test {
+ require Test::More;
+
+ my ($start, $end) = (0, 10000);
+ my $expected = [
+ 0, 1, 8, 11, 69, 88, 96, 101, 111, 181, 609, 619, 689, 808, 818, 888, 906, 916, 986, 1001, 1111, 1691, 1881, 1961, 6009, 6119, 6699, 6889, 6969, 8008, 8118, 8698, 8888, 8968, 9006, 9116, 9696, 9886, 9966
+ ];
+
+ my $strobos = [ map { strobotize($_) } $start .. $end ];
+ Test::More::is_deeply($strobos, $expected);
+ Test::More::done_testing();
+}
+
+my ($start, $end) = @ARGV;
+say for map { strobotize($_) } $start .. $end;
+
+
+__DATA__
+
+TASK #1 › Strobogrammatic Number
+Submitted by: Mohammad S Anwar
+
+A strobogrammatic number is a number that looks the same when looked at upside down.
+
+You are given two positive numbers $A and $B such that 1 <= $A <= $B <= 10^15.
+
+Write a script to print all strobogrammatic numbers between the given two numbers.
+Example
+
+Input: $A = 50, $B = 100
+ Output: 69, 88, 96
+
diff --git a/challenge-069/rage311/perl5/ch-2.pl b/challenge-069/rage311/perl5/ch-2.pl
new file mode 100644
index 0000000000..e60e42f9dd
--- /dev/null
+++ b/challenge-069/rage311/perl5/ch-2.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+
+use 5.032;
+use warnings;
+use feature 'signatures';
+no warnings 'experimental::signatures';
+
+sub zero_one ($i, $iterations = 30, $string = '') {
+ (my $tmp = reverse $string) =~ tr/01/10/;
+ $string .= '0' . $tmp;
+ say "S$i: \"$string\"" if $ENV{DEBUG};
+ return $string if $i == $iterations;
+ return zero_one(++$i, $iterations, $string);
+}
+
+say zero_one(1, $ARGV[0]);
+
+
+__DATA__
+
+TASK #2 › 0/1 String
+Submitted by: Mohammad S Anwar
+
+A 0/1 string is a string in which every character is either 0 or 1.
+
+Write a script to perform switch and reverse to generate S30 as described below:
+
+switch:
+
+Every 0 becomes 1 and every 1 becomes 0. For example, “101” becomes “010”.
+
+reverse:
+
+The string is reversed. For example, "001” becomes “100”.
+
+
+UPDATE (2020-07-13 17:00:00):
+
+It was brought to my notice that generating S1000 string would be nearly impossible. So I have decided to lower it down to S30. Please follow the rule as below:
+
+S0 = “”
+S1 = “0”
+S2 = “001”
+S3 = “0010011”
+…
+SN = SN-1 + “0” + switch(reverse(SN-1))
+