aboutsummaryrefslogtreecommitdiff
path: root/challenge-120
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-09 00:54:51 +0100
committerGitHub <noreply@github.com>2021-07-09 00:54:51 +0100
commit986bc95af0b29a8de06c08a60314bfc1376c6b68 (patch)
tree05f9a652b91a1b33f2783433fd76f28f75237c59 /challenge-120
parentfebf7224aab1afb04009c3bcdc91808e15f961b7 (diff)
parent1ebb82f4c952d34c126060dbbd24dd1ee30be33a (diff)
downloadperlweeklychallenge-club-986bc95af0b29a8de06c08a60314bfc1376c6b68.tar.gz
perlweeklychallenge-club-986bc95af0b29a8de06c08a60314bfc1376c6b68.tar.bz2
perlweeklychallenge-club-986bc95af0b29a8de06c08a60314bfc1376c6b68.zip
Merge pull request #4463 from oWnOIzRi/week120
add solution week 120 task 1 in perl
Diffstat (limited to 'challenge-120')
-rwxr-xr-xchallenge-120/steven-wilson/perl/ch-1.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-120/steven-wilson/perl/ch-1.pl b/challenge-120/steven-wilson/perl/ch-1.pl
new file mode 100755
index 0000000000..5b3cc9c087
--- /dev/null
+++ b/challenge-120/steven-wilson/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# TASK #1 > Swap Odd/Even bits
+
+use strict;
+use warnings;
+use feature qw/ say /;
+use Test::More;
+
+ok( swap_odd_even_bits(101) == 154, 'Input: $N = 101 Output: 154' );
+ok( swap_odd_even_bits(18) == 33, 'Input: $N = 18 Output: 33' );
+done_testing();
+
+sub swap_odd_even_bits {
+ my $input = shift;
+ my $binary = sprintf( "%08b", $input );
+ my $swapped = join( "", map { scalar reverse $_ } $binary =~ m/..?/g );
+ return oct( "0b" . $swapped );
+}