From 97f75e5e3dadf9b30b77c4aad2aa250ce8b4c68e Mon Sep 17 00:00:00 2001 From: Solathian Date: Sat, 2 Aug 2025 16:53:53 +0200 Subject: Added solution for challenge 332 --- challenge-332/solathian/perl/ch-1.pl | 11 +++++++++++ challenge-332/solathian/perl/ch-2.pl | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-332/solathian/perl/ch-1.pl create mode 100644 challenge-332/solathian/perl/ch-2.pl diff --git a/challenge-332/solathian/perl/ch-1.pl b/challenge-332/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..6fa2f460ba --- /dev/null +++ b/challenge-332/solathian/perl/ch-1.pl @@ -0,0 +1,11 @@ +use v5.40; +use List::Util qw(all); + +binaryDate("2025-07-26"); # "11111101001-111-11010" +binaryDate("2000-02-02"); # "11111010000-10-10" +binaryDate("2024-12-31"); # "11111101000-1100-11111" + +sub binaryDate($string) # it is assumed that the string is already of the correct format and is a valid date +{ + say join('-', map{sprintf("%b", $_)} split('-', $string)); +} \ No newline at end of file diff --git a/challenge-332/solathian/perl/ch-2.pl b/challenge-332/solathian/perl/ch-2.pl new file mode 100644 index 0000000000..b888320e4c --- /dev/null +++ b/challenge-332/solathian/perl/ch-2.pl @@ -0,0 +1,20 @@ +use v5.40; +use List::Util qw(all); + +isOdd("weekly"); # false +isOdd("challenge"); # false +isOdd("perl"); # true +isOdd("perl112"); # true +isOdd(""); # true + + + +sub isOdd($string) +{ + my %hash; + + $string =~ s/[^a-z]//gi; # remove everything which is not between 'a' and 'z', since it only mentioned letters + $hash{$_}++ foreach (split('', $string)); + ((all{$_ % 2 != 0} values %hash) and (scalar values %hash > 0)) ? say 'true' : say 'false'; +} + -- cgit