aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-192/james-smith/perl/ch-1.pl5
1 files changed, 5 insertions, 0 deletions
diff --git a/challenge-192/james-smith/perl/ch-1.pl b/challenge-192/james-smith/perl/ch-1.pl
index 4a347bc343..6526f74650 100644
--- a/challenge-192/james-smith/perl/ch-1.pl
+++ b/challenge-192/james-smith/perl/ch-1.pl
@@ -11,8 +11,13 @@ use Data::Dumper qw(Dumper);
my @TESTS = ( [5,2],[4,3],[6,1] );
is( binary_flip( $_->[0] ), $_->[1] ) for @TESTS;
+is( string_flip( $_->[0] ), $_->[1] ) for @TESTS;
done_testing();
+sub string_flip {
+ oct '0b'.sprintf('%b',$_[0])=~tr/01/10/r;
+}
+
sub binary_flip {
my($r,$k,$n) = (0,1,shift);
$r|=(~$n&1)<<$k++, $n>>=1 while $n;