aboutsummaryrefslogtreecommitdiff
path: root/challenge-329/e-choroba
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2025-07-07 11:32:11 +0200
committerE. Choroba <choroba@matfyz.cz>2025-07-07 11:32:11 +0200
commit8792c80ee45ab749a8e23b660b15e209cde3954a (patch)
tree5e6a7a9ea22e96b96273617f9f9c9764240ef0ac /challenge-329/e-choroba
parentbd7fce4bd5d085c209a213f2daca1e79799c9e87 (diff)
downloadperlweeklychallenge-club-8792c80ee45ab749a8e23b660b15e209cde3954a.tar.gz
perlweeklychallenge-club-8792c80ee45ab749a8e23b660b15e209cde3954a.tar.bz2
perlweeklychallenge-club-8792c80ee45ab749a8e23b660b15e209cde3954a.zip
Add solutions to 329: Counter Integers & Nice String by E. Choroba
Diffstat (limited to 'challenge-329/e-choroba')
-rwxr-xr-xchallenge-329/e-choroba/perl/ch-1.pl20
-rwxr-xr-xchallenge-329/e-choroba/perl/ch-2.pl20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-329/e-choroba/perl/ch-1.pl b/challenge-329/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..8a9710b26a
--- /dev/null
+++ b/challenge-329/e-choroba/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use List::Util qw{ uniq };
+
+sub counter_integers($str) {
+ return uniq(map 0 + $_, $str =~ /([0-9]+)/g)
+}
+
+use Test2::V0;
+plan(3 + 2);
+
+is [counter_integers('the1weekly2challenge2')], [1, 2], 'Example 1';
+is [counter_integers('go21od1lu5c7k')], [21, 1, 5, 7], 'Example 2';
+is [counter_integers('4p3e2r1l')], [4, 3, 2, 1], 'Example 3';
+
+is [counter_integers('a00b0c')], [0], 'Leading zeros';
+is [counter_integers('abc')], [], 'Empty';
diff --git a/challenge-329/e-choroba/perl/ch-2.pl b/challenge-329/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..ceefc0974d
--- /dev/null
+++ b/challenge-329/e-choroba/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub nice_string($str) {
+ my %seen;
+ $seen{lc $_} |= 1 + /[a-z]/ for $str =~ /[a-zA-Z]/g;
+ for my $char (keys %seen) {
+ next if 3 == $seen{$char}; # Seen both lower and upper-case.
+ $str =~ s/$char//gi;
+ }
+ return $str
+}
+
+use Test::More tests => 3;
+
+is nice_string('YaaAho'), 'aaA', 'Example 1';
+is nice_string('cC'), 'cC', 'Example 2';
+is nice_string('A'), '', 'Example 3';