diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2025-11-17 11:57:16 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2025-11-17 11:57:16 -0600 |
| commit | 22cd7d59124c392ad1fb8b5c4ca3e037197b8a5a (patch) | |
| tree | 29cfa346f83cf5d2a34fa262224211d2f7f97ee8 | |
| parent | 51f93bc0962522ed3bc5152f8266cc780c83f190 (diff) | |
| download | perlweeklychallenge-club-22cd7d59124c392ad1fb8b5c4ca3e037197b8a5a.tar.gz perlweeklychallenge-club-22cd7d59124c392ad1fb8b5c4ca3e037197b8a5a.tar.bz2 perlweeklychallenge-club-22cd7d59124c392ad1fb8b5c4ca3e037197b8a5a.zip | |
Solve PWC348
| -rw-r--r-- | challenge-348/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-348/wlmb/perl/ch-1.pl | 19 | ||||
| -rwxr-xr-x | challenge-348/wlmb/perl/ch-2.pl | 35 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-348/wlmb/blog.txt b/challenge-348/wlmb/blog.txt new file mode 100644 index 0000000000..992166a46c --- /dev/null +++ b/challenge-348/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/11/17/PWC348/ diff --git a/challenge-348/wlmb/perl/ch-1.pl b/challenge-348/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..628f5bd9d3 --- /dev/null +++ b/challenge-348/wlmb/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# Perl weekly challenge 348 +# Task 1: String Alike +# +# See https://wlmb.github.io/2025/11/17/PWC348/#task-1-string-alike +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S0 S1... + to check if string Sn can be split into equal length parts with the + same number of vowels + FIN +for(@ARGV){ + my $length=length(my $second=$_); + my $first=substr $second,0,$length/2,""; + my ($vowels_first, $vowels_second)= + map{tr/aeiouAEIOU//d}$first, $second; + my $result= $length%2==0 && $vowels_first == $vowels_second?"True":"False"; + say "$_-> $result"; +} diff --git a/challenge-348/wlmb/perl/ch-2.pl b/challenge-348/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..e945593048 --- /dev/null +++ b/challenge-348/wlmb/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +# Perl weekly challenge 348 +# Task 2: Covert Time +# +# See https://wlmb.github.io/2025/11/17/PWC348/#task-2-covert-time +use v5.36; +use feature qw(try); +use POSIX qw(floor); +die <<~"FIN" unless @ARGV and @ARGV%2==0; + Usage: $0 S0 T0 S1 T1... + to find how many operations (add 60, 15, 5 or 1 minute) are necessary to convert + the source time Sn to the target time Tn. The times are specified in the HH::MM + 24 hour format. + FIN +my @minutes_to_add=(60, 15, 5, 1); +for my($source, $target)(@ARGV){ + try { + my($source_mins, $target_mins) = map { + die "Wrong format: $_" unless /^(\d?\d):(\d{2})$/; + my ($hours, $minutes) = ($1, $2); + die "Invalid hours: $hours" unless 0<=$hours<24; + die "Invalid minutes: $minutes" unless 0<=$minutes<60; + $hours*60+$minutes + } $source, $target; + my $difference = ($target_mins - $source_mins)%(24*60); # modulo one day + my $operations = 0; + my $count; + $operations += $_ for map{ + ($count, $difference)=(floor($difference/$_), $difference%$_); + $count + } @minutes_to_add; + say "$source, $target -> $operations"; + } + catch($e){warn $e} +} |
