aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-17 02:57:18 +0100
committerGitHub <noreply@github.com>2020-07-17 02:57:18 +0100
commit76095e43974feb1b9b59839f476c439b5441e6c8 (patch)
treeb2014e5fc4875f54e099a17aac4c04b21e8afc6b
parent7e0c4c1f7538bfdd3108f1373011031e3a6351a9 (diff)
parenta19f49c909d5a5d5ce47de002140b62934295033 (diff)
downloadperlweeklychallenge-club-76095e43974feb1b9b59839f476c439b5441e6c8.tar.gz
perlweeklychallenge-club-76095e43974feb1b9b59839f476c439b5441e6c8.tar.bz2
perlweeklychallenge-club-76095e43974feb1b9b59839f476c439b5441e6c8.zip
Merge pull request #1949 from waltman/branch-for-challenge-069
Branch for challenge 069
-rw-r--r--challenge-069/walt-mankowski/perl/ch-1.pl5
-rw-r--r--challenge-069/walt-mankowski/python/ch-1.py12
-rw-r--r--challenge-069/walt-mankowski/python/ch-2.py17
3 files changed, 32 insertions, 2 deletions
diff --git a/challenge-069/walt-mankowski/perl/ch-1.pl b/challenge-069/walt-mankowski/perl/ch-1.pl
index 599be08898..c5e03de0db 100644
--- a/challenge-069/walt-mankowski/perl/ch-1.pl
+++ b/challenge-069/walt-mankowski/perl/ch-1.pl
@@ -25,6 +25,7 @@ for my $n ($A..$B) {
}
sub is_strobogrammatic($n) {
- my $flipped = join '', reverse map { $flip[$_] } split //, $n;
- return $n eq $flipped;
+ my $flipped = $n;
+ $flipped =~ tr/0123456789/01xxxx9x86/;
+ return $n eq scalar reverse $flipped;
}
diff --git a/challenge-069/walt-mankowski/python/ch-1.py b/challenge-069/walt-mankowski/python/ch-1.py
new file mode 100644
index 0000000000..d54f8e010d
--- /dev/null
+++ b/challenge-069/walt-mankowski/python/ch-1.py
@@ -0,0 +1,12 @@
+from sys import argv
+
+flip = [str(x) for x in [0, 1, 'x', 'x', 'x', 'x', 9, 'x', 8, 6]]
+
+def is_strobogrammatic(n):
+ flipped = n.translate(str.maketrans('0123456789', '01xxxx9x86'))[::-1]
+ return n == flipped
+
+A, B = [int(x) for x in argv[1:3]]
+for n in range(A, B+1):
+ if is_strobogrammatic(str(n)):
+ print(n)
diff --git a/challenge-069/walt-mankowski/python/ch-2.py b/challenge-069/walt-mankowski/python/ch-2.py
new file mode 100644
index 0000000000..c5e40e120b
--- /dev/null
+++ b/challenge-069/walt-mankowski/python/ch-2.py
@@ -0,0 +1,17 @@
+from sys import argv
+
+def S(n):
+ s = ''
+ for i in range(1, n+1):
+ s += '0' + switch(rev(s))
+
+ return s
+
+def switch(s):
+ return s.translate(str.maketrans('01', '10'))
+
+def rev(s):
+ return s[::-1]
+
+n = int(argv[1])
+print(S(n))