aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-120/james-smith/perl/ch-1.pl29
-rw-r--r--challenge-120/james-smith/perl/ch-2.pl22
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-120/james-smith/perl/ch-1.pl b/challenge-120/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..31b470c961
--- /dev/null
+++ b/challenge-120/james-smith/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ 101, 154 ],
+ [ 18, 33 ],
+);
+
+is( switch_bits($_->[0]), $_->[1] ) foreach @TESTS;
+is( switch_bits($_->[1]), $_->[0] ) foreach @TESTS;
+
+done_testing();
+
+## Similar to last weeks calculation. We and
+## with 10101010 to get the higher bits and
+## with 01010101 to get the lower bits...
+## and use bit shift operators to move them
+## left and right respectively.
+sub switch_bits {
+ ($_[0]&0xaa)>>1 | ($_[0]&0x55)<<1;
+}
+
diff --git a/challenge-120/james-smith/perl/ch-2.pl b/challenge-120/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..2348c8b946
--- /dev/null
+++ b/challenge-120/james-smith/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ 0, 1 ],
+);
+
+is( my_function($_->[0]), $_->[1] ) foreach @TESTS;
+
+done_testing();
+
+sub my_function {
+ return 1;
+}
+