From 9a07e50d0b214d9ecd1701a86387b39c4bf41a0a Mon Sep 17 00:00:00 2001 From: Torgny Lyon Date: Wed, 1 Oct 2025 21:26:24 +0200 Subject: Add solutions for week 341 --- challenge-341/torgny-lyon/blog.txt | 1 + challenge-341/torgny-lyon/perl/ch-1.pl | 18 ++++++++++++++++++ challenge-341/torgny-lyon/perl/ch-2.pl | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 challenge-341/torgny-lyon/blog.txt create mode 100755 challenge-341/torgny-lyon/perl/ch-1.pl create mode 100755 challenge-341/torgny-lyon/perl/ch-2.pl 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"); -- cgit