diff options
| author | Torgny Lyon <torgny@abc.se> | 2025-10-01 21:26:24 +0200 |
|---|---|---|
| committer | Torgny Lyon <torgny@abc.se> | 2025-10-01 21:26:24 +0200 |
| commit | 9a07e50d0b214d9ecd1701a86387b39c4bf41a0a (patch) | |
| tree | 6ba8b10aa17c1243ad9a31b31ef957558700b94f | |
| parent | c04ba8fd1d4060c8bc5e8a44fd1707c8bda205d9 (diff) | |
| download | perlweeklychallenge-club-9a07e50d0b214d9ecd1701a86387b39c4bf41a0a.tar.gz perlweeklychallenge-club-9a07e50d0b214d9ecd1701a86387b39c4bf41a0a.tar.bz2 perlweeklychallenge-club-9a07e50d0b214d9ecd1701a86387b39c4bf41a0a.zip | |
Add solutions for week 341
| -rw-r--r-- | challenge-341/torgny-lyon/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-341/torgny-lyon/perl/ch-1.pl | 18 | ||||
| -rwxr-xr-x | challenge-341/torgny-lyon/perl/ch-2.pl | 16 |
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-341/torgny-lyon/blog.txt b/challenge-341/torgny-lyon/blog.txt new file mode 100644 index 0000000000..e28f2f7938 --- /dev/null +++ b/challenge-341/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#341 diff --git a/challenge-341/torgny-lyon/perl/ch-1.pl b/challenge-341/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..28f1c99e17 --- /dev/null +++ b/challenge-341/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use v5.36; + +use Test::More tests => 5; + +sub count_words { + grep { + my $word = $_; + ! grep { index($word, $_) >= 0 } @{ $_[1] }; + } split / /, lc $_[0]; +} + +is(count_words('Hello World', ['d']), 1); +is(count_words('apple banana cherry', [ 'a', 'e' ]), 0); +is(count_words('Coding is fun', []), 3); +is(count_words('The Weekly Challenge', [ 'a', 'b' ]), 2); +is(count_words('Perl and Python', ['p']), 1); diff --git a/challenge-341/torgny-lyon/perl/ch-2.pl b/challenge-341/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..5712143816 --- /dev/null +++ b/challenge-341/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.36; + +use Test::More tests => 5; + +sub reverse_prefix { + my $i = index($_[0], $_[1]) + 1; + reverse(substr $_[0], 0, $i) . substr $_[0], $i; +} + +is(reverse_prefix("programming", "g"), "gorpramming"); +is(reverse_prefix("hello", "h"), "hello"); +is(reverse_prefix("abcdefghij", "h"), "hgfedcbaij"); +is(reverse_prefix("reverse", "s"), "srevere"); +is(reverse_prefix("perl", "r"), "repl"); |
