aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-03 20:26:34 +0100
committerGitHub <noreply@github.com>2021-07-03 20:26:34 +0100
commit63ed042c9ef56c982c37e050695f04887b5abe12 (patch)
tree841944ce2527757fd1698cefd0a99c18569a269f
parent8771b40b322033c23edd9027b056425137e9d324 (diff)
parentce7d7127188bec50ce008915a348ffe5765fcada (diff)
downloadperlweeklychallenge-club-63ed042c9ef56c982c37e050695f04887b5abe12.tar.gz
perlweeklychallenge-club-63ed042c9ef56c982c37e050695f04887b5abe12.tar.bz2
perlweeklychallenge-club-63ed042c9ef56c982c37e050695f04887b5abe12.zip
Merge pull request #4401 from lancew/119
Simple (unsafe) solution to task 1
-rw-r--r--challenge-119/lance-wicks/perl/ch-1.pl13
-rw-r--r--challenge-119/lance-wicks/perl/lib/Nibble.pm16
-rw-r--r--challenge-119/lance-wicks/perl/t/01-nibble.t9
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-119/lance-wicks/perl/ch-1.pl b/challenge-119/lance-wicks/perl/ch-1.pl
new file mode 100644
index 0000000000..60184364bb
--- /dev/null
+++ b/challenge-119/lance-wicks/perl/ch-1.pl
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+
+use lib './lib';
+use Nibble;
+my $nibble = Nibble->new;
+
+my $n = $ARGV[0];
+my $res = $nibble->swap($n);
+
+print "Input \$N = $n\n";
+print "Output: $res\n";
+
diff --git a/challenge-119/lance-wicks/perl/lib/Nibble.pm b/challenge-119/lance-wicks/perl/lib/Nibble.pm
new file mode 100644
index 0000000000..78d9c851b2
--- /dev/null
+++ b/challenge-119/lance-wicks/perl/lib/Nibble.pm
@@ -0,0 +1,16 @@
+package Nibble;
+
+use Moo;
+
+sub swap {
+ my ( $self, $n ) = @_;
+
+ my $oct = sprintf( "%08b", $n );
+
+ $oct =~ /^(.{4})(.{4})$/;
+
+ return oct "0b$2$1";
+}
+
+1;
+
diff --git a/challenge-119/lance-wicks/perl/t/01-nibble.t b/challenge-119/lance-wicks/perl/t/01-nibble.t
new file mode 100644
index 0000000000..8394f6a3c1
--- /dev/null
+++ b/challenge-119/lance-wicks/perl/t/01-nibble.t
@@ -0,0 +1,9 @@
+use Test2::V0 -target => 'Nibble';
+
+my @tests = ( [ 101, 86 ], [ 18, 33 ] );
+
+for (@tests) {
+ is $CLASS->swap( $_->[0] ), $_->[1], "$_->[0] returns $_->[1]";
+}
+
+done_testing;