aboutsummaryrefslogtreecommitdiff
path: root/challenge-002/james-smith
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-03 20:17:55 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-03 20:17:55 +0100
commit8f2a9c584fd921037ccfb8ec304865dae2d52796 (patch)
treedff053b0b647a39fd9d8e5babbf2738d56e3b3fa /challenge-002/james-smith
parentd579e514f4f37a998fb5efc74286b0cf413ad491 (diff)
downloadperlweeklychallenge-club-8f2a9c584fd921037ccfb8ec304865dae2d52796.tar.gz
perlweeklychallenge-club-8f2a9c584fd921037ccfb8ec304865dae2d52796.tar.bz2
perlweeklychallenge-club-8f2a9c584fd921037ccfb8ec304865dae2d52796.zip
- Added solution by "James A Smith" for challenge 002.
Diffstat (limited to 'challenge-002/james-smith')
-rw-r--r--challenge-002/james-smith/README1
-rw-r--r--challenge-002/james-smith/perl5/ch-1.sh3
-rw-r--r--challenge-002/james-smith/perl5/ch-2.pl13
-rw-r--r--challenge-002/james-smith/perl6/ch-1.sh1
-rw-r--r--challenge-002/james-smith/perl6/ch-2.p63
5 files changed, 21 insertions, 0 deletions
diff --git a/challenge-002/james-smith/README b/challenge-002/james-smith/README
new file mode 100644
index 0000000000..573d9eb02a
--- /dev/null
+++ b/challenge-002/james-smith/README
@@ -0,0 +1 @@
+Solution by James Smith
diff --git a/challenge-002/james-smith/perl5/ch-1.sh b/challenge-002/james-smith/perl5/ch-1.sh
new file mode 100644
index 0000000000..b7cb3bfea7
--- /dev/null
+++ b/challenge-002/james-smith/perl5/ch-1.sh
@@ -0,0 +1,3 @@
+perl -E 'say /^0*(\d+(?:[.]\d+)?)/?$1:$_ for @ARGV' 121 0.012 -012 002 000
+
+perl -E 'say s/^0+(?=\d)//r for @ARGV' 42983832 16031952 1089991
diff --git a/challenge-002/james-smith/perl5/ch-2.pl b/challenge-002/james-smith/perl5/ch-2.pl
new file mode 100644
index 0000000000..e807b1731a
--- /dev/null
+++ b/challenge-002/james-smith/perl5/ch-2.pl
@@ -0,0 +1,13 @@
+use strict;
+
+sub base35 {
+ my $o = '';
+ for( shift; $_; ) {
+ $_ = ( $_ - (my $t = $_%35) )/ 35;
+ $o .= chr $t+($t<10?48:55);
+ }
+ return scalar reverse $o;
+}
+
+print $_,"\t", base35( $_ ),"\n" foreach @ARGV;
+
diff --git a/challenge-002/james-smith/perl6/ch-1.sh b/challenge-002/james-smith/perl6/ch-1.sh
new file mode 100644
index 0000000000..c4ef1e4e0a
--- /dev/null
+++ b/challenge-002/james-smith/perl6/ch-1.sh
@@ -0,0 +1 @@
+perl6 -e 'say m/^0*(\d+[.\d+]?)/??"$0"!!$_ for @*ARGS' 121 0.012 -012 002 000
diff --git a/challenge-002/james-smith/perl6/ch-2.p6 b/challenge-002/james-smith/perl6/ch-2.p6
new file mode 100644
index 0000000000..80d37995c2
--- /dev/null
+++ b/challenge-002/james-smith/perl6/ch-2.p6
@@ -0,0 +1,3 @@
+sub mp($n) {chr $n+($n < 10??48!!55)}
+sub b35($n) {$n??b35(floor $n/35)~mp($n%35)!!''}
+say b35 $_ for @*ARGS;