diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2025-07-26 17:30:00 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2025-07-26 17:30:00 -0600 |
| commit | 9e414cb78e14126e546d8305a01ed98241f4b5e6 (patch) | |
| tree | 554efe04541d35167b1a32df6c52e0dd0e8a34ce | |
| parent | 1ff2c9796a511d63231d3757acb27e4046a91fb2 (diff) | |
| download | perlweeklychallenge-club-9e414cb78e14126e546d8305a01ed98241f4b5e6.tar.gz perlweeklychallenge-club-9e414cb78e14126e546d8305a01ed98241f4b5e6.tar.bz2 perlweeklychallenge-club-9e414cb78e14126e546d8305a01ed98241f4b5e6.zip | |
Solve PWC332
| -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" +} |
