diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2024-09-16 13:31:54 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2024-09-16 13:31:54 -0600 |
| commit | fced8c82c54301c4c10e12c92822d9d227b22a92 (patch) | |
| tree | c72e036232c7834da062ee995cf6424f7f907929 | |
| parent | e2b636cb707cb468a0edb1f12c758720cc1407e1 (diff) | |
| download | perlweeklychallenge-club-fced8c82c54301c4c10e12c92822d9d227b22a92.tar.gz perlweeklychallenge-club-fced8c82c54301c4c10e12c92822d9d227b22a92.tar.bz2 perlweeklychallenge-club-fced8c82c54301c4c10e12c92822d9d227b22a92.zip | |
Solve PWC287
| -rw-r--r-- | challenge-287/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-287/wlmb/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-287/wlmb/perl/ch-2.pl | 21 |
3 files changed, 44 insertions, 0 deletions
diff --git a/challenge-287/wlmb/blog.txt b/challenge-287/wlmb/blog.txt new file mode 100644 index 0000000000..9076be72ee --- /dev/null +++ b/challenge-287/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/09/16/PWC287/ diff --git a/challenge-287/wlmb/perl/ch-1.pl b/challenge-287/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..06db6ab211 --- /dev/null +++ b/challenge-287/wlmb/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# Perl weekly challenge 287 +# Task 1: Strong Password +# +# See https://wlmb.github.io/2024/09/16/PWC287/#task-1-strong-password +use v5.36; +use List::Util qw(max); +die <<~"FIN" unless @ARGV; + Usage: $0 P1 P2... + to find the minimum number of steps required to convert + the passwords Pi into strong passwords + FIN +for(@ARGV){ + my $single_triad=/^(.)\1\1$/; + my $missing_classes=(!/[a-z]/)+(!/[A-Z]/)+(!/[0-9]/); + my $triads=0; + ++$triads while /(.)\1\1/g; + my $missing_classes=max($missing_classes-$triads, 0); + my $missing_chars=max(6-(length)-$missing_classes, 0); + my $steps=$single_triad?3:$triads+$missing_chars+$missing_classes; + say "$_ -> $steps"; +} diff --git a/challenge-287/wlmb/perl/ch-2.pl b/challenge-287/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..f0a3244324 --- /dev/null +++ b/challenge-287/wlmb/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +# Perl weekly challenge 287 +# Task 2: Valid Number +# +# See https://wlmb.github.io/2024/09/16/PWC287/#task-2-valid-number +use v5.36; +my $re = qr/ + ^ # start of string + (\+|-)? # optional sign + (\d+ # integer + | \d+\.\d* # or integer part and optional decimal part + | \d*\.\d+ # or optional integer part and decimal part + ) + ( # exponent + (e|E) # letter e or E + (\+|-)? # optional sign + \d+ # integer exponent + )? # is optional + $ # end of string + /x; +say "$_ -> ", /$re/?"true":"false" for (@ARGV); |
