aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <adam.russell@optum.com>2019-04-03 16:08:53 -0400
committerAdam Russell <adam.russell@optum.com>2019-04-03 16:08:53 -0400
commit3abeddeb2a6e6eb0074879ec3cf6c67c36952467 (patch)
tree05b2d9b3bc6a7013e88129734a752f0fd8d3ed57
parente658f5c0aa5f41c468d60e1a62779b3cbb96412e (diff)
parentf72e62a4db7b80c9171fb150bcfd212d345498ff (diff)
downloadperlweeklychallenge-club-3abeddeb2a6e6eb0074879ec3cf6c67c36952467.tar.gz
perlweeklychallenge-club-3abeddeb2a6e6eb0074879ec3cf6c67c36952467.tar.bz2
perlweeklychallenge-club-3abeddeb2a6e6eb0074879ec3cf6c67c36952467.zip
Merge remote-tracking branch 'upstream/master'
-rw-r--r--challenge-001/adam-russell/perl5/ch-1.pl14
-rw-r--r--challenge-001/adam-russell/perl5/ch-2.pl28
-rw-r--r--challenge-001/james-smith/README1
-rw-r--r--challenge-001/james-smith/perl5/ch-1.sh1
-rw-r--r--challenge-001/james-smith/perl5/ch-2.sh1
-rw-r--r--challenge-002/abigail/README1
-rw-r--r--challenge-002/arpad-toth/perl5/ch-1.pl18
-rw-r--r--challenge-002/arpad-toth/perl5/ch-2.pl48
-rw-r--r--challenge-002/athanasius/perl5/ch-1.pl29
-rw-r--r--challenge-002/athanasius/perl5/ch-2.pl106
-rw-r--r--challenge-002/fred-zinn/perl5/ch-1.pl7
-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
-rw-r--r--challenge-002/jo-christian-oterhals/perl5/base35.pl49
-rw-r--r--challenge-002/jo-christian-oterhals/perl5/ch-1.sh1
-rw-r--r--challenge-002/jo-christian-oterhals/perl5/ch-2.sh3
-rw-r--r--challenge-002/jo-christian-oterhals/perl6/ch-1.sh1
-rw-r--r--challenge-002/jo-christian-oterhals/perl6/ch-2.sh1
-rw-r--r--challenge-002/nick-logan/perl5/ch-1.pl1
-rw-r--r--challenge-002/nick-logan/perl5/ch-2.pl9
-rw-r--r--challenge-002/nick-logan/perl5/to-base35.pl11
-rw-r--r--challenge-002/nick-logan/perl6/ch-1.p61
-rw-r--r--challenge-002/nick-logan/perl6/ch-2.p69
-rw-r--r--challenge-002/nick-logan/perl6/to-base35.p611
-rw-r--r--challenge-002/steven-wilson/perl5/ch-1.pl17
-rw-r--r--challenge-002/steven-wilson/perl5/ch-2.pl55
-rw-r--r--[-rwxr-xr-x]members.json2
30 files changed, 446 insertions, 0 deletions
diff --git a/challenge-001/adam-russell/perl5/ch-1.pl b/challenge-001/adam-russell/perl5/ch-1.pl
index ff50d0f18d..af82fa4dc8 100644
--- a/challenge-001/adam-russell/perl5/ch-1.pl
+++ b/challenge-001/adam-russell/perl5/ch-1.pl
@@ -1,4 +1,5 @@
use strict;
+<<<<<<< HEAD
use warnings;
##
# Challenge #1
@@ -10,3 +11,16 @@ my $number=do{
$challenge_string=~tr/e/E/
};
print "$number $challenge_string\n";
+=======
+use warnings;
+##
+# Challenge #1
+# Write a script to replace the character 'e' with 'E' in the string 'Perl Weekly Challenge'.
+# Also print the number of times the character 'e' is found in the string.
+##
+my $challenge_string = "Perl Weekly Challenge";
+my $number = do {
+ $challenge_string =~ tr/e/E/;
+};
+print "$number $challenge_string\n";
+>>>>>>> upstream/master
diff --git a/challenge-001/adam-russell/perl5/ch-2.pl b/challenge-001/adam-russell/perl5/ch-2.pl
index e2671d51f8..4dfebdfbe3 100644
--- a/challenge-001/adam-russell/perl5/ch-2.pl
+++ b/challenge-001/adam-russell/perl5/ch-2.pl
@@ -1,4 +1,5 @@
use strict;
+<<<<<<< HEAD
use warnings;
##
# Challenge #2
@@ -24,5 +25,32 @@ my $i = 1;
}
}
$i++;
+=======
+use warnings;
+##
+# Challenge #2
+# Write one-liner to solve FizzBuzz problem and print number 1-20.
+# However, any number divisible by 3 should be replaced by the word fizz
+# and any divisible by 5 by the word buzz. Numbers divisible by both become fizz buzz.
+##
+use experimental q/switch/;
+my $i = 1;
+{
+ given($i){
+ when($i % 3 == 0 && $i % 5 == 0){
+ print "fizz buzz\n";
+ }
+ when($i % 5 == 0){
+ print "buzz\n";
+ }
+ when($i % 3 == 0){
+ print "fizz\n";
+ }
+ default{
+ print "$i\n";
+ }
+ }
+ $i++;
+>>>>>>> upstream/master
redo until ($i > 20);
}
diff --git a/challenge-001/james-smith/README b/challenge-001/james-smith/README
new file mode 100644
index 0000000000..573d9eb02a
--- /dev/null
+++ b/challenge-001/james-smith/README
@@ -0,0 +1 @@
+Solution by James Smith
diff --git a/challenge-001/james-smith/perl5/ch-1.sh b/challenge-001/james-smith/perl5/ch-1.sh
new file mode 100644
index 0000000000..70435d35ec
--- /dev/null
+++ b/challenge-001/james-smith/perl5/ch-1.sh
@@ -0,0 +1 @@
+perl -E 'say my $n = (my $s = "Perl Weekly Challenge" )=~ y/e/E/; say $s;'
diff --git a/challenge-001/james-smith/perl5/ch-2.sh b/challenge-001/james-smith/perl5/ch-2.sh
new file mode 100644
index 0000000000..1e375cd941
--- /dev/null
+++ b/challenge-001/james-smith/perl5/ch-2.sh
@@ -0,0 +1 @@
+perl -E 'say "".($_%3?"":"Fizz").($_%5?"":"Buzz")||$_ for 1..20;'
diff --git a/challenge-002/abigail/README b/challenge-002/abigail/README
new file mode 100644
index 0000000000..5f0d73ae16
--- /dev/null
+++ b/challenge-002/abigail/README
@@ -0,0 +1 @@
+Solution by Abigail
diff --git a/challenge-002/arpad-toth/perl5/ch-1.pl b/challenge-002/arpad-toth/perl5/ch-1.pl
new file mode 100644
index 0000000000..7ca1c664df
--- /dev/null
+++ b/challenge-002/arpad-toth/perl5/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl -w
+use strict;
+
+=pod
+
+=head1 Perl Weekly Challenge #002-1
+
+ Write a script or one-liner to remove leading zeros from positive numbers.
+ eg '00034' result should be '34'
+
+ one liner solution
+ perl -le '$ARGV[0] =~ s/^0+// && print $ARGV[0]' 000023
+
+=cut
+
+exit;
+
+
diff --git a/challenge-002/arpad-toth/perl5/ch-2.pl b/challenge-002/arpad-toth/perl5/ch-2.pl
new file mode 100644
index 0000000000..66d0d2a031
--- /dev/null
+++ b/challenge-002/arpad-toth/perl5/ch-2.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+use strict;
+use v5.10;
+=pod
+
+=head1 Perl Weekly Challenge #002-2
+ Write a script that can convert integers to and from a base35 representation, using the characters 0-9 and A-Y.
+ note: argument checking is not completely safe, was not part of the solution.
+
+=cut
+
+unless((scalar(@ARGV)==2) && ($ARGV[0] =~/tobase35|frombase35/)){
+say <<USAGE;
+usage: chw2_2.pl <options>
+ tobase35 - convert decimal integer to base35
+ frombase35 - convert base35 number to decimal
+ number
+examples: chw2_2.pl tobase35 256, should print '7b'
+ chw2_2.pl frombase35 7b, should print '256'
+USAGE
+exit;
+}
+
+my $string="";
+my $demal = 0;
+
+process($ARGV[0],$ARGV[1]);
+
+sub process {
+my ($option, $number) = @_;
+if ($option eq "tobase35") {
+ $number = int($number);
+ while($number){
+ $string .= ('0'..'9','A'..'Z')[$number % 35];
+ $number = int($number/35);
+ }
+say scalar(reverse($string));
+}
+else {
+ $number = uc($number);
+ for my $char (split(//,$number)){
+ $demal = 35*$demal + index("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",$char);
+ }
+say $demal;
+}
+}
+exit;
+
diff --git a/challenge-002/athanasius/perl5/ch-1.pl b/challenge-002/athanasius/perl5/ch-1.pl
new file mode 100644
index 0000000000..f831efa8d8
--- /dev/null
+++ b/challenge-002/athanasius/perl5/ch-1.pl
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+while (my $n = <DATA>)
+{
+ chomp $n;
+
+ if ($n =~ / ^ \+? \. \d+ $ /x ||
+ $n =~ s/ ^ (\+?) 0* (\d+ \.? \d*) $ /$1$2/x)
+ {
+ print "$n\n";
+ }
+ else
+ {
+ print "$n is not a positive number\n";
+ }
+}
+
+__DATA__
+00012345
++0678
+0000090.123
++00456.789
+0.123
+000.123
+0
+00
+.123
+-01
diff --git a/challenge-002/athanasius/perl5/ch-2.pl b/challenge-002/athanasius/perl5/ch-2.pl
new file mode 100644
index 0000000000..17e15af2f7
--- /dev/null
+++ b/challenge-002/athanasius/perl5/ch-2.pl
@@ -0,0 +1,106 @@
+use strict;
+use warnings;
+use Const::Fast;
+
+const my $ZERO => ord('0');
+const my $NINE => ord('9');
+const my $A => ord('A');
+const my $Y => ord('Y');
+const my @DIGITS => ('0' .. '9', 'A' .. 'Y');
+const my @POWERS => get_powers();
+
+while (my $n = <DATA>)
+{
+ chomp $n;
+ my $p = base35to10($n);
+ my $q = base10to35($p);
+ printf "%8s(35) = %11s(10) = %8s(35)\n", $n, $p, $q;
+}
+
+sub base35to10
+{
+ my ($base35) = @_;
+ my $base10 = 0;
+ my $power = 1;
+
+ for my $digit (reverse split //, $base35)
+ {
+ $base10 += digit35to10($digit) * $power;
+ $power *= 35;
+ }
+
+ return $base10;
+}
+
+sub base10to35
+{
+ my ($base10) = @_;
+
+ $base10 < $POWERS[-1] or die "Number $base10 too large, stopped";
+
+ my $index = get_highest_index($base10);
+ my $base35 = '';
+
+ for my $i (reverse 0 .. $index)
+ {
+ my $digit = $DIGITS[ int($base10 / $POWERS[$i]) ];
+ $base35 .= $digit;
+ $base10 %= $POWERS[$i];
+ }
+
+ return $base35;
+}
+
+sub get_highest_index
+{
+ my ($base10) = @_;
+ my $index = $#POWERS;
+
+ for my $i (reverse 1 .. $#POWERS - 1)
+ {
+ last if $base10 >= $POWERS[$i];
+ $index = $i - 1;
+ }
+
+ return $index;
+}
+
+sub digit35to10
+{
+ my ($digit) = @_;
+ my $ord = ord($digit);
+
+ return $digit if $ord >= $ZERO && $ord <= $NINE;
+ return ($ord - $A + 10) if $ord >= $A && $ord <= $Y;
+
+ die "Unknown base-35 digit '$digit', stopped";
+}
+
+sub get_powers
+{
+ my @powers;
+ my $power = 1;
+
+ for (1 .. 13)
+ {
+ push @powers, $power;
+ $power *= 35;
+ }
+
+ return @powers;
+}
+
+__DATA__
+10
+17
+35
+52
+A
+1A
+100
+ABC
+123
+36
+0
+13579BEH
+4
diff --git a/challenge-002/fred-zinn/perl5/ch-1.pl b/challenge-002/fred-zinn/perl5/ch-1.pl
new file mode 100644
index 0000000000..e9327bac42
--- /dev/null
+++ b/challenge-002/fred-zinn/perl5/ch-1.pl
@@ -0,0 +1,7 @@
+@a1= ( "00123", "-00123", "123" );
+foreach $nr (@a1) {
+ if (substr($nr,0,1) == '0') { $nr =~ s/^0*//; }
+ print "($nr)\n";
+}
+
+
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;
diff --git a/challenge-002/jo-christian-oterhals/perl5/base35.pl b/challenge-002/jo-christian-oterhals/perl5/base35.pl
new file mode 100644
index 0000000000..921b84bd0c
--- /dev/null
+++ b/challenge-002/jo-christian-oterhals/perl5/base35.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+#
+# Filename: base35.pl
+#
+# Usage:
+# perl base35.pl [+-]NUMBER FROM-BASE, e.g.
+#
+# perl base35.pl 1000 10
+# Output: SK
+#
+# perl base35.pl SK 35
+# Output: 1000
+#
+# perl base35.pl -SK 35
+# Output: -1000
+use v5.18;
+say base35_conv(@ARGV);
+sub base35_conv {
+ my ($no, $base) = (uc(shift), shift);
+ if ($base != 10 && $base != 35) {
+ warn "Not a valid base, must be 10 or 35";
+ return -1;
+ }
+ if (($base == 35 && $no !~ /^[\+\-]{0,1}[0-9A-Y]+$/) || ($base == 10 && $no !~ /^[\+\-]{0,1}[0-9]+$/)) {
+ warn "You have to provide a valid number for the given base";
+ return -1;
+ }
+ my ($c, $e) = (0, 0);
+ my $prefix = $no =~ s/^(\+|-)// ? $1 : "";
+ my %d = map { if ($base == 35) { $_ => $c++ } else { $c++ => $_ } } (0..9,'A'..'Y');
+ if ($base == 35) {
+ my $i = 1;
+ for (reverse(split("", $no))) {
+ $e += $i * $d{$_};
+ $i = $i * 35;
+ }
+ }
+ else {
+ my @digits;
+ while ($no > 0) {
+ push @digits, $d{$no % 35};
+ $no = int($no / 35);
+ }
+ $e = join("", reverse(@digits));
+ }
+ return ( $prefix ? $prefix : "" ) . $e;
+}
+
+
diff --git a/challenge-002/jo-christian-oterhals/perl5/ch-1.sh b/challenge-002/jo-christian-oterhals/perl5/ch-1.sh
new file mode 100644
index 0000000000..adaa66e050
--- /dev/null
+++ b/challenge-002/jo-christian-oterhals/perl5/ch-1.sh
@@ -0,0 +1 @@
+perl -E 'say "001000"*1;'
diff --git a/challenge-002/jo-christian-oterhals/perl5/ch-2.sh b/challenge-002/jo-christian-oterhals/perl5/ch-2.sh
new file mode 100644
index 0000000000..757fdd3fd1
--- /dev/null
+++ b/challenge-002/jo-christian-oterhals/perl5/ch-2.sh
@@ -0,0 +1,3 @@
+perl -E '%d = map { $_ => $c++ } (0..9,A..Y); $i = 1; for (reverse(split("", @ARGV[0]))) { $e += $i * $d{$_}; $i = $i * 35; } say $e' 1M5
+
+perl -E '%d = map { $c++ => $_ } (0..9,A..Y); while ($ARGV[0] > 0) { push @n, $d{$ARGV[0] % 35}; $ARGV[0] = int($ARGV[0] / 35); } say join("", reverse(@n));' 2000
diff --git a/challenge-002/jo-christian-oterhals/perl6/ch-1.sh b/challenge-002/jo-christian-oterhals/perl6/ch-1.sh
new file mode 100644
index 0000000000..e254f8b3f2
--- /dev/null
+++ b/challenge-002/jo-christian-oterhals/perl6/ch-1.sh
@@ -0,0 +1 @@
+perl6 -e 'say "-001000"*1;'
diff --git a/challenge-002/jo-christian-oterhals/perl6/ch-2.sh b/challenge-002/jo-christian-oterhals/perl6/ch-2.sh
new file mode 100644
index 0000000000..72476f64e0
--- /dev/null
+++ b/challenge-002/jo-christian-oterhals/perl6/ch-2.sh
@@ -0,0 +1 @@
+perl6 -e 'say "1M5".parse-base(35)'
diff --git a/challenge-002/nick-logan/perl5/ch-1.pl b/challenge-002/nick-logan/perl5/ch-1.pl
new file mode 100644
index 0000000000..f7787b8a04
--- /dev/null
+++ b/challenge-002/nick-logan/perl5/ch-1.pl
@@ -0,0 +1 @@
+my @ARGV = do { sub eval($_) { &EVAL($_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; print("$_\n") for map &{ sub ($_) { /^0(0|1|2|3|4|5|6|7|8|9)+/ and (0+$_) or $_ } }.(), @ARGV;
diff --git a/challenge-002/nick-logan/perl5/ch-2.pl b/challenge-002/nick-logan/perl5/ch-2.pl
new file mode 100644
index 0000000000..f6d6226cda
--- /dev/null
+++ b/challenge-002/nick-logan/perl5/ch-2.pl
@@ -0,0 +1,9 @@
+my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
+my ($state, $result, $dict, $base35) = (1, "", {}, @ARGV[0]);
+$dict{$_} = $_ for "1".."9";
+$dict{$_} = ord($_) - 55 for "A".."Y";
+for (reverse grep &{ sub ($_) { $_ ne "" } }.(), split("", $base35)) {
+ $result += $state * $dict{$_};
+ $state *= 35;
+};
+print("$result\n");
diff --git a/challenge-002/nick-logan/perl5/to-base35.pl b/challenge-002/nick-logan/perl5/to-base35.pl
new file mode 100644
index 0000000000..683acda914
--- /dev/null
+++ b/challenge-002/nick-logan/perl5/to-base35.pl
@@ -0,0 +1,11 @@
+# bin/to-base35
+sub to_int($_) { my @i = split(/"."/, $_[0]); @i[0] };
+my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
+my ($result, $dict, $base10) = ("", {}, @ARGV[0]);
+$dict{$_} = $_ for "1".."9";
+$dict{ord($_) - 55} = $_ for "A".."Y";
+while ($base10 > 0) {
+ $result = join("", $dict{to_int($base10 % 35)}, $result);
+ $base10 = to_int($base10 / 35);
+}
+print("$result\n");
diff --git a/challenge-002/nick-logan/perl6/ch-1.p6 b/challenge-002/nick-logan/perl6/ch-1.p6
new file mode 100644
index 0000000000..f7787b8a04
--- /dev/null
+++ b/challenge-002/nick-logan/perl6/ch-1.p6
@@ -0,0 +1 @@
+my @ARGV = do { sub eval($_) { &EVAL($_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; print("$_\n") for map &{ sub ($_) { /^0(0|1|2|3|4|5|6|7|8|9)+/ and (0+$_) or $_ } }.(), @ARGV;
diff --git a/challenge-002/nick-logan/perl6/ch-2.p6 b/challenge-002/nick-logan/perl6/ch-2.p6
new file mode 100644
index 0000000000..f6d6226cda
--- /dev/null
+++ b/challenge-002/nick-logan/perl6/ch-2.p6
@@ -0,0 +1,9 @@
+my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
+my ($state, $result, $dict, $base35) = (1, "", {}, @ARGV[0]);
+$dict{$_} = $_ for "1".."9";
+$dict{$_} = ord($_) - 55 for "A".."Y";
+for (reverse grep &{ sub ($_) { $_ ne "" } }.(), split("", $base35)) {
+ $result += $state * $dict{$_};
+ $state *= 35;
+};
+print("$result\n");
diff --git a/challenge-002/nick-logan/perl6/to-base35.p6 b/challenge-002/nick-logan/perl6/to-base35.p6
new file mode 100644
index 0000000000..683acda914
--- /dev/null
+++ b/challenge-002/nick-logan/perl6/to-base35.p6
@@ -0,0 +1,11 @@
+# bin/to-base35
+sub to_int($_) { my @i = split(/"."/, $_[0]); @i[0] };
+my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
+my ($result, $dict, $base10) = ("", {}, @ARGV[0]);
+$dict{$_} = $_ for "1".."9";
+$dict{ord($_) - 55} = $_ for "A".."Y";
+while ($base10 > 0) {
+ $result = join("", $dict{to_int($base10 % 35)}, $result);
+ $base10 = to_int($base10 / 35);
+}
+print("$result\n");
diff --git a/challenge-002/steven-wilson/perl5/ch-1.pl b/challenge-002/steven-wilson/perl5/ch-1.pl
new file mode 100644
index 0000000000..37c7b9c5bb
--- /dev/null
+++ b/challenge-002/steven-wilson/perl5/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-04-03
+# Challenge #1
+# Write a script or one-liner to remove leading zeros from positive numbers.
+#
+# Usage: $ ./week2c1 0099
+
+use warnings;
+use strict;
+use feature qw/ say /;
+
+my ($number) = @ARGV;
+
+$number =~ /[0]*(\d+)/;
+
+say $1;
diff --git a/challenge-002/steven-wilson/perl5/ch-2.pl b/challenge-002/steven-wilson/perl5/ch-2.pl
new file mode 100644
index 0000000000..1726baf8a3
--- /dev/null
+++ b/challenge-002/steven-wilson/perl5/ch-2.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-04-02
+# Challenge #2
+# Write a script that can convert integers to and from a base35
+# representation, using the characters 0-9 and A-Y. Dave Jacoby came up with
+# nice description about base35, in case you needed some background.
+#
+# Usage: ./week2c2 <number> [enc|dec]
+# eg:
+# $ ./week2c2 13 enc, encodes 13 in base 10 to D in base 35.
+# $ ./week2c2 10 dec, decodes 10 in base 35 to 35 in base 10.
+
+use warnings;
+use strict;
+use feature qw/ say /;
+
+my @digits = qw / 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q
+ R S T U V W X Y /;
+
+my ( $number, $operation ) = @ARGV;
+
+if ( $operation eq "enc" ) {
+ say "$number encoded in base 35 is ", base35_encode($number);
+}
+elsif ( $operation eq "dec" ) {
+ say "$number decoded from base 35 is ", base35_decode($number);
+}
+
+sub base35_encode {
+ my $number = shift;
+ my @answer;
+ while ( $number > 34 ) {
+ unshift @answer, $digits[ $number % 35 ];
+ $number = $number / 35;
+ }
+ unshift @answer, $digits[$number];
+ return @answer;
+}
+
+sub base35_decode {
+ my $number = shift;
+ my @number_as_array = split( //, $number );
+ my $number_length = @number_as_array;
+ my $answer = 0;
+ my $counter = 0;
+ my $digit_in_base10;
+ for ( my $i = $number_length - 1; $i >= 0; $i-- ) {
+ ($digit_in_base10)
+ = grep { $digits[$_] eq $number_as_array[$counter] } ( 0 .. 34 );
+ $answer += $digit_in_base10 * 35**$i;
+ $counter++;
+ }
+ return $answer;
+}
diff --git a/members.json b/members.json
index 691f122452..2979970c30 100755..100644
--- a/members.json
+++ b/members.json
@@ -1,4 +1,5 @@
{
+ "abigail" : "Abigail",
"alex-daniel" : "Alex Daniel",
"alexander-karelas" : "Alexander Karelas",
"alexey-melezhik" : "Alexey Melezhik",
@@ -38,6 +39,7 @@
"michael-schaap" : "Michael Schaap",
"neil-bowers" : "Neil Bowers",
"nick-logan" : "Nick Logan",
+ "ohmycloud" : "Chenyf",
"oleskii-tsvietnov" : "Oleskii Tsvitenov",
"ozzy" : "Ozzy",
"pavel-jurca" : "Pavel Jurca",