diff options
| -rw-r--r-- | challenge-332/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-332/wlmb/perl/ch-1.pl | 28 | ||||
| -rwxr-xr-x | challenge-332/wlmb/perl/ch-2.pl | 16 |
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-332/wlmb/blog.txt b/challenge-332/wlmb/blog.txt new file mode 100644 index 0000000000..c3e11757b0 --- /dev/null +++ b/challenge-332/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/07/26/PWC332/ diff --git a/challenge-332/wlmb/perl/ch-1.pl b/challenge-332/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..70930f680b --- /dev/null +++ b/challenge-332/wlmb/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +# Perl weekly challenge 332 +# Task 1: Binary Date +# +# See https://wlmb.github.io/2025/07/26/PWC332/#task-1-binary-date +use v5.36; +use feature 'try'; +die <<~"FIN" unless @ARGV; + Usage: $0 D1 D2... + to map the ISO dates Dn in the format YYYY-MM-DD to binary. + FIN +my @days=(0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); +for(@ARGV){ + try { + die "Invalid format: $_" unless /^(\d{4})-(\d{2})-(\d{2})$/; + my ($year, $month, $day)=($1, $2, $3); + die "Invalid month: $_" unless 1<=$month<=12; + die "Invalid day: $_" unless 1<=$day<=$days[$month]; + die "Invalid day: $_" if $month==2 && $day==29 && !leap($year); + say "$_ -> ", join "-", map {sprintf "%b", $_} ($year, $month, $day); + } + catch($e){ + say $e; + } +} +sub leap($year){ + return $year%400==0 || $year%4==0 && $year%100 != 0; +} diff --git a/challenge-332/wlmb/perl/ch-2.pl b/challenge-332/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..46250527c3 --- /dev/null +++ b/challenge-332/wlmb/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +# Perl weekly challenge 332 +# Task 2: Odd Letters +# +# See https://wlmb.github.io/2025/07/26/PWC332/#task-2-odd-letters +use v5.36; +use List::Util qw(all); +die <<~"FIN" unless @ARGV; + Usage: $0 W1 W2... + to check if all letters in word Wn appear an odd number of times + FIN +for(@ARGV){ + my %count; + $count{$_}++ for split ""; + say "$_ -> ", (all{$_%2} values %count)?"True":"False" +} |
