From 3fcad6f9d8a29ef71019749eb53864fb25516a22 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Wed, 23 Jun 2021 18:59:15 +0200 Subject: Solution to task 1 --- challenge-118/jo-37/perl/ch-1.pl | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 challenge-118/jo-37/perl/ch-1.pl (limited to 'challenge-118') diff --git a/challenge-118/jo-37/perl/ch-1.pl b/challenge-118/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..66a2391037 --- /dev/null +++ b/challenge-118/jo-37/perl/ch-1.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0 '!float'; +use PDL; +use Math::Prime::Util qw(fromdigits todigits); + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <slice('-1:0'); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is bin_pal(5), T(), 'example 1'; + is bin_pal(4), F(), 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + my @head = '1'; + push @head, int rand 2 for 0 .. 2047; + + my $n = fromdigits([@head, reverse @head], 2); + is bin_pal($n), T(), + 'random 4096 bit binary palindrome'; + is bin_pal($n - 1), F(), + 'one off random binary palindrome'; + } + + done_testing; + exit; +} -- cgit