diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-13 02:43:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-13 02:43:31 +0100 |
| commit | 56386b31b4b77b116ecdef66a385b2b099d48e35 (patch) | |
| tree | 65b85c6d5713cb260d8d3636fa59bd4821cdc556 | |
| parent | 95ffb49c07e858b9e3da706310e73453233c1261 (diff) | |
| parent | cc1e0f89c996e9486d40a8968104169882fd1bab (diff) | |
| download | perlweeklychallenge-club-56386b31b4b77b116ecdef66a385b2b099d48e35.tar.gz perlweeklychallenge-club-56386b31b4b77b116ecdef66a385b2b099d48e35.tar.bz2 perlweeklychallenge-club-56386b31b4b77b116ecdef66a385b2b099d48e35.zip | |
Merge pull request #4497 from PerlBoy1967/branch-for-challenge-121
Task 1
| -rwxr-xr-x | challenge-121/perlboy1967/perl/ch-1.pl | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-121/perlboy1967/perl/ch-1.pl b/challenge-121/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..81d9837877 --- /dev/null +++ b/challenge-121/perlboy1967/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 121 +# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-121/#TASK1 +# +# Task 1 - Invert Bit +# +# Author: Niels 'PerlBoy' van Dijke + +use v5.16; +use strict; +use warnings; + +use Test::More; + +# Prototype(s) +sub invertBit($$); + +my $tests = [ + [ 12, 3, 8], + [ 18, 4, 26], + [ 0b10101010, 5, 0b10111010 ], + [ 0b111111111111, 8, 0b111101111111 ], +]; + +foreach my $t (@$tests) { + printf "%s\n", join(',', @$t) unless is(invertBit($t->[0],$t->[1]), $t->[2]); +} + +done_testing(); + +sub invertBit($$) { + my ($m,$n) = @_; + + return $m ^ (1 << ($n-1)); +} |
