diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-10-10 17:21:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-10 17:21:10 +0100 |
| commit | 157e5c06fbc769eb482e6a6484d9f9d76f19f547 (patch) | |
| tree | c2cd595603a013d5ad3ee519aa68b0c884fd4bf0 | |
| parent | ea3c13ee9b68a723d09fc3ea665e677693b46b98 (diff) | |
| parent | 8d278f426f8f7358942b1a07cbd15cdf9afd7501 (diff) | |
| download | perlweeklychallenge-club-157e5c06fbc769eb482e6a6484d9f9d76f19f547.tar.gz perlweeklychallenge-club-157e5c06fbc769eb482e6a6484d9f9d76f19f547.tar.bz2 perlweeklychallenge-club-157e5c06fbc769eb482e6a6484d9f9d76f19f547.zip | |
Merge pull request #12826 from torgnylyon/master
Add solutions for week 342
| -rw-r--r-- | challenge-342/torgny-lyon/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-342/torgny-lyon/perl/ch-1.pl | 26 | ||||
| -rwxr-xr-x | challenge-342/torgny-lyon/perl/ch-2.pl | 19 |
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-342/torgny-lyon/blog.txt b/challenge-342/torgny-lyon/blog.txt new file mode 100644 index 0000000000..2c287d1630 --- /dev/null +++ b/challenge-342/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#342 diff --git a/challenge-342/torgny-lyon/perl/ch-1.pl b/challenge-342/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..563bb3e3f3 --- /dev/null +++ b/challenge-342/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use v5.36; + +use Test::More tests => 5; + +use List::Util qw(mesh); + +sub balance_string { + my @letters = sort $_[0] =~ /[a-z]/g; + my @digits = sort $_[0] =~ /\d/g; + if (@digits == @letters) { + return join q{}, mesh \@digits, \@letters; + } elsif (@digits == @letters + 1) { + return join q{}, grep { defined } mesh \@digits, \@letters; + } elsif (@letters == @digits + 1) { + return join q{}, grep { defined } mesh \@letters, \@digits; + } + q{}; +} + +is(balance_string("a0b1c2"), "0a1b2c"); +is(balance_string("abc12"), "a1b2c"); +is(balance_string("0a2b1c3"), "0a1b2c3"); +is(balance_string("1a23"), q{}); +is(balance_string("ab123"), "1a2b3"); diff --git a/challenge-342/torgny-lyon/perl/ch-2.pl b/challenge-342/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..25d666b0ef --- /dev/null +++ b/challenge-342/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use v5.36; + +use Test::More tests => 5; + +use List::Util qw(max); + +sub get_max_score { + max map { + (() = substr($_[0], 0, $_) =~ /0/g) + (() = substr($_[0], $_) =~ /1/g) + } 1..(length($_[0]) - 1); +} + +is(get_max_score("0011"), 4); +is(get_max_score("0000"), 3); +is(get_max_score("1111"), 3); +is(get_max_score("0101"), 3); +is(get_max_score("011101"), 5); |
