From 5d9ea33ce7523bf5cea555a24ca530800d87592a Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 18 Aug 2025 22:45:28 +0000 Subject: w332 - Task 1 & 2 --- challenge-332/perlboy1967/perl/ch1.pl | 29 +++++++++++++++++++++++++++++ challenge-332/perlboy1967/perl/ch2.pl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 challenge-332/perlboy1967/perl/ch1.pl create mode 100755 challenge-332/perlboy1967/perl/ch2.pl diff --git a/challenge-332/perlboy1967/perl/ch1.pl b/challenge-332/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..0bdbeb7207 --- /dev/null +++ b/challenge-332/perlboy1967/perl/ch1.pl @@ -0,0 +1,29 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Binary Date +Submitted by: Mohammad Sajid Anwar + +You are given a date in the format YYYY-MM-DD. + +Write a script to convert it into binary date. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +sub binaryDate ($date) { + $date =~ s/(\d+)(\D+)(\d+)(\D+)(\d+)/sprintf("%b$2%b$4%b",$1,$3,$5)/er; +} + +is(binaryDate('2025-07-26'),'11111101001-111-11010','Example 1'); +is(binaryDate('2000-02-02'),'11111010000-10-10','Example 2'); +is(binaryDate('2024-12-31'),'11111101000-1100-11111','Example 3'); + +done_testing; diff --git a/challenge-332/perlboy1967/perl/ch2.pl b/challenge-332/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..66583498e5 --- /dev/null +++ b/challenge-332/perlboy1967/perl/ch2.pl @@ -0,0 +1,34 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Odd Letters +Submitted by: Mohammad Sajid Anwar + +You are given a string. + +Write a script to find out if each letter in the given string appeared odd number of times. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use boolean; +use List::MoreUtils qw(frequency all); + +sub oddLetters ($str) { + my %f = frequency(split //, $str); + boolean all { $_ % 2 == 1 } values %f; +} + +is(oddLetters('weekly'),false,'Example 1'); +is(oddLetters('perl'),true,'Example 2'); +is(oddLetters('challenge'),false,'Example 3'); +is(oddLetters('PerlBoy'),true,'Own example'); + +done_testing; -- cgit