aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-10-01 02:47:49 +0100
committerGitHub <noreply@github.com>2025-10-01 02:47:49 +0100
commitabd3020576b7fc82affe37136002d16878ee1566 (patch)
treea3cb3bce6f07241a6d8a59f083431edab595d7f0
parent9c8f18b314a965e4d2f88638b92c05294839e230 (diff)
parent9103f0d2752aafd44d250aea368defe79e2c22cd (diff)
downloadperlweeklychallenge-club-abd3020576b7fc82affe37136002d16878ee1566.tar.gz
perlweeklychallenge-club-abd3020576b7fc82affe37136002d16878ee1566.tar.bz2
perlweeklychallenge-club-abd3020576b7fc82affe37136002d16878ee1566.zip
Merge pull request #12768 from packy/master
Challenge 341 solutions by Packy Anderson
-rw-r--r--challenge-340/packy-anderson/README.md2
-rw-r--r--challenge-340/packy-anderson/blog.txt4
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/elixir/ch-1.exs0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/elixir/ch-2.exs0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/perl/ch-1.pl0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/perl/ch-2.pl0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/python/ch-1.py0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/python/ch-2.py0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/raku/ch-1.raku0
-rwxr-xr-x[-rw-r--r--]challenge-340/packy-anderson/raku/ch-2.raku0
-rw-r--r--challenge-341/packy-anderson/README.md2
-rw-r--r--challenge-341/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-341/packy-anderson/elixir/ch-1.exs44
-rwxr-xr-xchallenge-341/packy-anderson/elixir/ch-2.exs28
-rwxr-xr-xchallenge-341/packy-anderson/perl/ch-1.pl34
-rwxr-xr-xchallenge-341/packy-anderson/perl/ch-2.pl28
-rwxr-xr-xchallenge-341/packy-anderson/python/ch-1.py36
-rwxr-xr-xchallenge-341/packy-anderson/python/ch-2.py24
-rwxr-xr-xchallenge-341/packy-anderson/raku/ch-1.raku34
-rwxr-xr-xchallenge-341/packy-anderson/raku/ch-2.raku28
20 files changed, 263 insertions, 2 deletions
diff --git a/challenge-340/packy-anderson/README.md b/challenge-340/packy-anderson/README.md
index 1013ff24f7..7af85bca11 100644
--- a/challenge-340/packy-anderson/README.md
+++ b/challenge-340/packy-anderson/README.md
@@ -23,4 +23,4 @@
## Blog Post
-[Perl Weekly Challenge: Points? What's the diff?](https://packy.dardan.com/b/bN)
+[Perl Weekly Challenge: Rising in Num](https://packy.dardan.com/b/bj)
diff --git a/challenge-340/packy-anderson/blog.txt b/challenge-340/packy-anderson/blog.txt
index 1c748f0baf..2de2f4218b 100644
--- a/challenge-340/packy-anderson/blog.txt
+++ b/challenge-340/packy-anderson/blog.txt
@@ -1 +1,5 @@
+<<<<<<< HEAD
+https://packy.dardan.com/b/bj
+=======
https://packy.dardan.com/2025/09/23/perl-weekly-challenge-rising-in-num/
+>>>>>>> upstream/master
diff --git a/challenge-340/packy-anderson/elixir/ch-1.exs b/challenge-340/packy-anderson/elixir/ch-1.exs
index 65013250fc..65013250fc 100644..100755
--- a/challenge-340/packy-anderson/elixir/ch-1.exs
+++ b/challenge-340/packy-anderson/elixir/ch-1.exs
diff --git a/challenge-340/packy-anderson/elixir/ch-2.exs b/challenge-340/packy-anderson/elixir/ch-2.exs
index 73a47e15f8..73a47e15f8 100644..100755
--- a/challenge-340/packy-anderson/elixir/ch-2.exs
+++ b/challenge-340/packy-anderson/elixir/ch-2.exs
diff --git a/challenge-340/packy-anderson/perl/ch-1.pl b/challenge-340/packy-anderson/perl/ch-1.pl
index 80cb0b4f84..80cb0b4f84 100644..100755
--- a/challenge-340/packy-anderson/perl/ch-1.pl
+++ b/challenge-340/packy-anderson/perl/ch-1.pl
diff --git a/challenge-340/packy-anderson/perl/ch-2.pl b/challenge-340/packy-anderson/perl/ch-2.pl
index 0dc1b498f1..0dc1b498f1 100644..100755
--- a/challenge-340/packy-anderson/perl/ch-2.pl
+++ b/challenge-340/packy-anderson/perl/ch-2.pl
diff --git a/challenge-340/packy-anderson/python/ch-1.py b/challenge-340/packy-anderson/python/ch-1.py
index 4b0733e391..4b0733e391 100644..100755
--- a/challenge-340/packy-anderson/python/ch-1.py
+++ b/challenge-340/packy-anderson/python/ch-1.py
diff --git a/challenge-340/packy-anderson/python/ch-2.py b/challenge-340/packy-anderson/python/ch-2.py
index 55b4f2b288..55b4f2b288 100644..100755
--- a/challenge-340/packy-anderson/python/ch-2.py
+++ b/challenge-340/packy-anderson/python/ch-2.py
diff --git a/challenge-340/packy-anderson/raku/ch-1.raku b/challenge-340/packy-anderson/raku/ch-1.raku
index 9bd7914c33..9bd7914c33 100644..100755
--- a/challenge-340/packy-anderson/raku/ch-1.raku
+++ b/challenge-340/packy-anderson/raku/ch-1.raku
diff --git a/challenge-340/packy-anderson/raku/ch-2.raku b/challenge-340/packy-anderson/raku/ch-2.raku
index 935d273a0b..935d273a0b 100644..100755
--- a/challenge-340/packy-anderson/raku/ch-2.raku
+++ b/challenge-340/packy-anderson/raku/ch-2.raku
diff --git a/challenge-341/packy-anderson/README.md b/challenge-341/packy-anderson/README.md
index 1013ff24f7..704729b966 100644
--- a/challenge-341/packy-anderson/README.md
+++ b/challenge-341/packy-anderson/README.md
@@ -23,4 +23,4 @@
## Blog Post
-[Perl Weekly Challenge: Points? What's the diff?](https://packy.dardan.com/b/bN)
+[Perl Weekly Challenge: Something just BROKE](https://packy.dardan.com/b/bw)
diff --git a/challenge-341/packy-anderson/blog.txt b/challenge-341/packy-anderson/blog.txt
new file mode 100644
index 0000000000..3c44456bdb
--- /dev/null
+++ b/challenge-341/packy-anderson/blog.txt
@@ -0,0 +1 @@
+https://packy.dardan.com/b/bw \ No newline at end of file
diff --git a/challenge-341/packy-anderson/elixir/ch-1.exs b/challenge-341/packy-anderson/elixir/ch-1.exs
new file mode 100755
index 0000000000..398e7b8b91
--- /dev/null
+++ b/challenge-341/packy-anderson/elixir/ch-1.exs
@@ -0,0 +1,44 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+ def broken_keys(str, []) do
+ # if there are no broken keys,
+ # we can type all the words
+ String.split(str)
+ |> Enum.count
+ end
+
+ def broken_keys(str, keys) do
+ # build a character class
+ {:ok, regex} = Regex.compile(
+ "[" <> Enum.join(keys) <> "]", [:caseless]
+ )
+ # count how many words don't match the class
+ String.split(str)
+ |> Enum.filter(fn word -> not Regex.match?(regex, word) end)
+ |> Enum.count
+ end
+
+ def solution(str, keys) do
+ keylist = keys
+ |> Enum.map(fn c -> "'#{c}'" end)
+ |> Enum.join(",")
+ IO.puts("Input: $str = '#{str}, @keys = (#{keylist})'")
+ IO.puts("Output: #{broken_keys(str, keys)}")
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution("Hello World", ["d"])
+
+IO.puts("\nExample 2:")
+PWC.solution("apple banana cherry", ["a", "e"])
+
+IO.puts("\nExample 3:")
+PWC.solution("Coding is fun", [])
+
+IO.puts("\nExample 4:")
+PWC.solution("The Weekly Challenge", ["a","b"])
+
+IO.puts("\nExample 5:")
+PWC.solution("Perl and Python", ["p"])
diff --git a/challenge-341/packy-anderson/elixir/ch-2.exs b/challenge-341/packy-anderson/elixir/ch-2.exs
new file mode 100755
index 0000000000..710d80716a
--- /dev/null
+++ b/challenge-341/packy-anderson/elixir/ch-2.exs
@@ -0,0 +1,28 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+ def reverse_prefix(str, char) do
+ [a, b] = String.split(str, char, parts: 2)
+ char <> String.reverse(a) <> b
+ end
+
+ def solution(str, char) do
+ IO.puts("Input: $str = \"#{str}\", $char = \"#{char}\"")
+ IO.puts("Output: \"#{reverse_prefix(str, char)}\"")
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution("programming", "g")
+
+IO.puts("\nExample 2:")
+PWC.solution("hello", "h")
+
+IO.puts("\nExample 3:")
+PWC.solution("abcdefghij", "h")
+
+IO.puts("\nExample 4:")
+PWC.solution("reverse", "s")
+
+IO.puts("\nExample 5:")
+PWC.solution("perl","r")
diff --git a/challenge-341/packy-anderson/perl/ch-1.pl b/challenge-341/packy-anderson/perl/ch-1.pl
new file mode 100755
index 0000000000..5156de78b6
--- /dev/null
+++ b/challenge-341/packy-anderson/perl/ch-1.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+use v5.40;
+
+sub brokenKeys($str, @keys) {
+ my @words = split /\s+/, $str;
+ # if there are no broken keys,
+ # we can type all the words
+ return scalar(@words) if @keys == 0;
+ # build a character class
+ my $regex = '[' . join('', @keys) . ']';
+ # count how many words don't match the class
+ return ( scalar( grep {! /$regex/i } @words) );
+}
+
+sub solution($str, $keys) {
+ my $keylist = join ",", map {"'$_'"} @$keys;
+ say "Input: \$str = '$str', \@keys = ($keylist)";
+ say "Output: " . brokenKeys($str, @$keys);
+}
+
+say "Example 1:";
+solution("Hello World", ["d"]);
+
+say "\nExample 2:";
+solution("apple banana cherry", ["a", "e"]);
+
+say "\nExample 3:";
+solution("Coding is fun", []);
+
+say "\nExample 4:";
+solution("The Weekly Challenge", ["a","b"]);
+
+say "\nExample 5:";
+solution("Perl and Python", ["p"]); \ No newline at end of file
diff --git a/challenge-341/packy-anderson/perl/ch-2.pl b/challenge-341/packy-anderson/perl/ch-2.pl
new file mode 100755
index 0000000000..c925939b15
--- /dev/null
+++ b/challenge-341/packy-anderson/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use v5.40;
+
+sub reversePrefix($str, $char) {
+ my $loc = index($str, $char) + 1;
+ reverse(substr($str, 0, $loc)) . substr($str, $loc);
+}
+
+sub solution($str, $char) {
+ say qq{Input: \$str = "$str", \$char = "$char"};
+ my $result = reversePrefix($str, $char);
+ say qq{Output: "$result"};
+}
+
+say "Example 1:";
+solution("programming", "g");
+
+say "\nExample 2:";
+solution("hello", "h");
+
+say "\nExample 3:";
+solution("abcdefghij", "h");
+
+say "\nExample 4:";
+solution("reverse", "s");
+
+say "\nExample 5:";
+solution("perl","r");
diff --git a/challenge-341/packy-anderson/python/ch-1.py b/challenge-341/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..ecd60e168f
--- /dev/null
+++ b/challenge-341/packy-anderson/python/ch-1.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import re
+
+def broken_keys(mystr, keys):
+ words = mystr.split()
+ # if there are no broken keys,
+ # we can type all the words
+ if len(keys) == 0: return len(words)
+ # build a character class
+ regex = re.compile('[' + ''.join(keys) + ']', re.I)
+ # count how many words don't match the class
+ return( len([
+ word for word in words if not re.search(regex, word)
+ ]) )
+
+def solution(mystr, keys):
+ keylist = ",".join([ f"'{c}'" for c in keys ])
+ print(f"Input: $str = '{mystr}', @keys = ({keylist})")
+ print(f"Output: {broken_keys(mystr, keys)}")
+
+
+print('Example 1:')
+solution("Hello World", ["d"])
+
+print('\nExample 2:')
+solution("apple banana cherry", ["a", "e"])
+
+print('\nExample 3:')
+solution("Coding is fun", [])
+
+print('\nExample 4:')
+solution("The Weekly Challenge", ["a","b"])
+
+print('\nExample 5:')
+solution("Perl and Python", ["p"])
diff --git a/challenge-341/packy-anderson/python/ch-2.py b/challenge-341/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..0265f90a2a
--- /dev/null
+++ b/challenge-341/packy-anderson/python/ch-2.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+def reverse_prefix(mystr, char):
+ loc = mystr.find(char) + 1
+ return mystr[0:loc][::-1] + mystr[loc:]
+
+def solution(mystr, char):
+ print(f'Input: $str = "{mystr}", $char = "{char}"')
+ print(f'Output: "{reverse_prefix(mystr, char)}"')
+
+print('Example 1:')
+solution("programming", "g")
+
+print('\nExample 2:')
+solution("hello", "h")
+
+print('\nExample 3:')
+solution("abcdefghij", "h")
+
+print('\nExample 4:')
+solution("reverse", "s")
+
+print('\nExample 5:')
+solution("perl","r")
diff --git a/challenge-341/packy-anderson/raku/ch-1.raku b/challenge-341/packy-anderson/raku/ch-1.raku
new file mode 100755
index 0000000000..f400d13c4c
--- /dev/null
+++ b/challenge-341/packy-anderson/raku/ch-1.raku
@@ -0,0 +1,34 @@
+#!/usr/bin/env raku
+use v6;
+
+sub brokenKeys($str, @keys) {
+ my @words = $str.comb(/\S+/);
+ # if there are no broken keys,
+ # we can type all the words
+ return @words.elems if @keys == 0;
+ # build a character class
+ my $regex = '<[' ~ @keys.join ~ ']>';
+ # count how many words don't match the class
+ return ( ( @words.grep({! /:i <$regex>/ }) ).elems );
+}
+
+sub solution($str, @keys) {
+ my $keys = @keys.map({"'$_'"}).join(",");
+ say "Input: \$str = '$str', \@keys = ($keys)";
+ say "Output: " ~ brokenKeys($str, @keys);
+}
+
+say "Example 1:";
+solution("Hello World", ["d"]);
+
+say "\nExample 2:";
+solution("apple banana cherry", ["a", "e"]);
+
+say "\nExample 3:";
+solution("Coding is fun", []);
+
+say "\nExample 4:";
+solution("The Weekly Challenge", ["a","b"]);
+
+say "\nExample 5:";
+solution("Perl and Python", ["p"]); \ No newline at end of file
diff --git a/challenge-341/packy-anderson/raku/ch-2.raku b/challenge-341/packy-anderson/raku/ch-2.raku
new file mode 100755
index 0000000000..739c2d8fed
--- /dev/null
+++ b/challenge-341/packy-anderson/raku/ch-2.raku
@@ -0,0 +1,28 @@
+#!/usr/bin/env raku
+use v6;
+
+sub reversePrefix($str, $char) {
+ my $loc = $str.index($char) + 1;
+ $str.substr(0, $loc).flip ~ $str.substr($loc);
+}
+
+sub solution($str, $char) {
+ say qq{Input: \$str = "$str", \$char = "$char"};
+ my $result = reversePrefix($str, $char);
+ say qq{Output: "$result"};
+}
+
+say "Example 1:";
+solution("programming", "g");
+
+say "\nExample 2:";
+solution("hello", "h");
+
+say "\nExample 3:";
+solution("abcdefghij", "h");
+
+say "\nExample 4:";
+solution("reverse", "s");
+
+say "\nExample 5:";
+solution("perl","r");