aboutsummaryrefslogtreecommitdiff
path: root/challenge-192/james-smith
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-11-21 21:00:17 +0000
committerGitHub <noreply@github.com>2022-11-21 21:00:17 +0000
commitc9b9e079f49982e2b4106c0dcd552b4fdbe92d90 (patch)
tree46cfd6d6621aeb74877e9623bce0ee32d7637288 /challenge-192/james-smith
parent96da103ba96c50d324397c33e79626cdcf977182 (diff)
downloadperlweeklychallenge-club-c9b9e079f49982e2b4106c0dcd552b4fdbe92d90.tar.gz
perlweeklychallenge-club-c9b9e079f49982e2b4106c0dcd552b4fdbe92d90.tar.bz2
perlweeklychallenge-club-c9b9e079f49982e2b4106c0dcd552b4fdbe92d90.zip
Update ch-1.pl
Diffstat (limited to 'challenge-192/james-smith')
-rw-r--r--challenge-192/james-smith/perl/ch-1.pl11
1 files changed, 11 insertions, 0 deletions
diff --git a/challenge-192/james-smith/perl/ch-1.pl b/challenge-192/james-smith/perl/ch-1.pl
index b2e18ab4be..c3066f12db 100644
--- a/challenge-192/james-smith/perl/ch-1.pl
+++ b/challenge-192/james-smith/perl/ch-1.pl
@@ -13,6 +13,7 @@ my @TESTS = ( [5,2],[4,3],[6,1] );
is( binary_flip( $_->[0] ), $_->[1] ) for @TESTS;
is( string_flip( $_->[0] ), $_->[1] ) for @TESTS;
is( c_flip( $_->[0] ), $_->[1] ) for @TESTS;
+is( c2_flip( $_->[0] ), $_->[1] ) for @TESTS;
done_testing();
sub string_flip {
@@ -36,3 +37,13 @@ int c_flip(int n) {
}
return r;
}
+
+int c2_flip(int n) {
+ int o = n;
+ int m = 1;
+ while(o>>=1) {
+ m<<=1;
+ m++;
+ }
+ return n^m;
+}