diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-07-05 11:51:47 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-07-05 11:51:47 +0100 |
| commit | 7724f41709fab6db7dcd3ed4343dab68d72a734b (patch) | |
| tree | e1d25c214b1ec18f0d9bbe9dd3f9247e5ff654d0 | |
| parent | 1c091cc2ecee5b4940089e91e763b6e8aa06fd7c (diff) | |
| download | perlweeklychallenge-club-7724f41709fab6db7dcd3ed4343dab68d72a734b.tar.gz perlweeklychallenge-club-7724f41709fab6db7dcd3ed4343dab68d72a734b.tar.bz2 perlweeklychallenge-club-7724f41709fab6db7dcd3ed4343dab68d72a734b.zip | |
first pass at solution using & | << and >>
| -rw-r--r-- | challenge-120/james-smith/perl/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-120/james-smith/perl/ch-2.pl | 22 |
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; +} + |
