From 2b24043f65ec899e96cfa0081e2e432047bfc4e7 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 5 Jul 2021 14:53:16 +0200 Subject: Solution to task 1 --- challenge-120/jo-37/perl/ch-1.pl | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 challenge-120/jo-37/perl/ch-1.pl (limited to 'challenge-120') diff --git a/challenge-120/jo-37/perl/ch-1.pl b/challenge-120/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..ca6f560789 --- /dev/null +++ b/challenge-120/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use experimental 'signatures'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <> 1 | ($n & $odd) << 1; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is swap_bits(101), 154, 'example 1'; + is swap_bits(18), 33, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + is swap_bits(0), 0, 'no bit set'; + is swap_bits(~0), ~0, 'all bits set'; + is swap_bits(0x55555555), 0xaaaaaaaa, 'odd to even'; + is swap_bits(0xaaaaaaaa), 0x55555555, 'even to odd'; + } + + done_testing; + exit; +} -- cgit From e2a94c137fa8b35eab32d3d2dabaf28ec622691b Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 5 Jul 2021 19:25:34 +0200 Subject: Solution to task 2 --- challenge-120/jo-37/perl/ch-2.pl | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 challenge-120/jo-37/perl/ch-2.pl (limited to 'challenge-120') diff --git a/challenge-120/jo-37/perl/ch-2.pl b/challenge-120/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..2ee102cb6d --- /dev/null +++ b/challenge-120/jo-37/perl/ch-2.pl @@ -0,0 +1,82 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use experimental 'signatures'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <