aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-22 09:31:02 +0100
committerGitHub <noreply@github.com>2024-07-22 09:31:02 +0100
commitf9135963d2e34ff7a4bb0ba2384f94eaa2fc1473 (patch)
tree0cf4d55b23534a562250e1931d69e579598312e6
parent03e2e7cae2fc04901ad15f2207af10b0f118e2f9 (diff)
parent5598c2ce58954b9fa56c460bb77a0e923c29a369 (diff)
downloadperlweeklychallenge-club-f9135963d2e34ff7a4bb0ba2384f94eaa2fc1473.tar.gz
perlweeklychallenge-club-f9135963d2e34ff7a4bb0ba2384f94eaa2fc1473.tar.bz2
perlweeklychallenge-club-f9135963d2e34ff7a4bb0ba2384f94eaa2fc1473.zip
Merge pull request #10468 from packy/master
Challenge 279 solutions by Packy Anderson
-rw-r--r--challenge-279/packy-anderson/README.md2
-rw-r--r--challenge-279/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-279/packy-anderson/elixir/ch-1.exs40
-rwxr-xr-xchallenge-279/packy-anderson/elixir/ch-2.exs27
-rwxr-xr-xchallenge-279/packy-anderson/perl/ch-1.pl38
-rwxr-xr-xchallenge-279/packy-anderson/perl/ch-2.pl23
-rwxr-xr-xchallenge-279/packy-anderson/python/ch-1.py36
-rwxr-xr-xchallenge-279/packy-anderson/python/ch-2.py21
-rwxr-xr-xchallenge-279/packy-anderson/raku/ch-1.raku34
-rwxr-xr-xchallenge-279/packy-anderson/raku/ch-2.raku20
10 files changed, 241 insertions, 1 deletions
diff --git a/challenge-279/packy-anderson/README.md b/challenge-279/packy-anderson/README.md
index 738aeb6df0..4143afe86f 100644
--- a/challenge-279/packy-anderson/README.md
+++ b/challenge-279/packy-anderson/README.md
@@ -22,4 +22,4 @@
## Blog Post
-[Perl Weekly Challenge: Word Reverse String Sort](https://packy.dardan.com/b/P9)
+[Perl Weekly Challenge: Split 'em away!](https://packy.dardan.com/b/PP)
diff --git a/challenge-279/packy-anderson/blog.txt b/challenge-279/packy-anderson/blog.txt
new file mode 100644
index 0000000000..2df55801aa
--- /dev/null
+++ b/challenge-279/packy-anderson/blog.txt
@@ -0,0 +1 @@
+https://packy.dardan.com/b/PP \ No newline at end of file
diff --git a/challenge-279/packy-anderson/elixir/ch-1.exs b/challenge-279/packy-anderson/elixir/ch-1.exs
new file mode 100755
index 0000000000..5c16d782d7
--- /dev/null
+++ b/challenge-279/packy-anderson/elixir/ch-1.exs
@@ -0,0 +1,40 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+ def sortLetters(letters, weights) do
+ Enum.zip(weights, letters)
+ |> Enum.sort_by( &( &1 |> Tuple.to_list |> List.first ))
+ |> Enum.map_join("", &( &1 |> Tuple.to_list |> List.last ))
+ end
+
+ def solution(letters, weights) do
+ IO.puts("Input: @letters = ('" <>
+ Enum.join(letters, "', '") <> "')"
+ )
+ IO.puts(" @weights = (" <>
+ Enum.join(weights, ", ") <> ")"
+ )
+ IO.puts("Output: " <> sortLetters(letters, weights) )
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution(
+ ['R', 'E', 'P', 'L'], [3, 2, 1, 4]
+)
+
+IO.puts("\nExample 2:")
+PWC.solution(
+ ['A', 'U', 'R', 'K'], [2, 4, 1, 3]
+)
+
+IO.puts("\nExample 3:")
+PWC.solution(
+ ['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]
+)
+
+IO.puts("\nExample 4:")
+PWC.solution(
+ [ 'C', 'd', 'F', 'i', 'l', 'n', 'o', 'o', 's', 'u'],
+ [ 1, 4, 5, 8, 3, 10, 9, 2, 7, 6]
+)
diff --git a/challenge-279/packy-anderson/elixir/ch-2.exs b/challenge-279/packy-anderson/elixir/ch-2.exs
new file mode 100755
index 0000000000..fc55f51ae3
--- /dev/null
+++ b/challenge-279/packy-anderson/elixir/ch-2.exs
@@ -0,0 +1,27 @@
+#!/usr/bin/env elixir
+
+defmodule PWC do
+ require Integer
+ def splitString(str) do
+ str
+ |> String.downcase
+ |> String.graphemes
+ |> Enum.filter(&( String.match?(&1, ~r/[aeiou]/) ))
+ |> Kernel.length
+ |> Integer.is_even
+ end
+
+ def solution(str) do
+ IO.puts("Input: $str = \"#{str}\"")
+ IO.puts("Output: " <> to_string(splitString(str)) )
+ end
+end
+
+IO.puts("Example 1:")
+PWC.solution("perl")
+
+IO.puts("\nExample 2:")
+PWC.solution("book")
+
+IO.puts("\nExample 3:")
+PWC.solution("good morning")
diff --git a/challenge-279/packy-anderson/perl/ch-1.pl b/challenge-279/packy-anderson/perl/ch-1.pl
new file mode 100755
index 0000000000..9ec3202299
--- /dev/null
+++ b/challenge-279/packy-anderson/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+use v5.40;
+
+use List::AllUtils qw( zip );
+
+sub sortLetters($letters, $weights) {
+ my %letters = zip @$weights, @$letters;
+ return join q{}, map {
+ $letters{$_}
+ } sort { $a <=> $b } keys %letters;
+}
+
+sub solution($letters, $weights) {
+ say 'Input: @letters = (\'' . join('\', \'', @$letters) . '\')';
+ say ' @weights = (' . join(', ', @$weights) . ')';
+ say 'Output: ' . sortLetters($letters, $weights);
+}
+
+say "Example 1:";
+solution(
+ ['R', 'E', 'P', 'L'], [3, 2, 1, 4]
+);
+
+say "\nExample 2:";
+solution(
+ ['A', 'U', 'R', 'K'], [2, 4, 1, 3]
+);
+
+say "\nExample 3:";
+solution(
+ ['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]
+);
+
+say "\nExample 4:";
+solution(
+ [ 'C', 'd', 'F', 'i', 'l', 'n', 'o', 'o', 's', 'u'],
+ [ 1, 4, 5, 8, 3, 10, 9, 2, 7, 6]
+); \ No newline at end of file
diff --git a/challenge-279/packy-anderson/perl/ch-2.pl b/challenge-279/packy-anderson/perl/ch-2.pl
new file mode 100755
index 0000000000..0e1d69a44b
--- /dev/null
+++ b/challenge-279/packy-anderson/perl/ch-2.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use v5.40;
+
+sub splitString($str) {
+ return (
+ ( grep { /[aeiou]/i } split //, $str ) % 2 == 0
+ ? 'True' : 'False'
+ );
+}
+
+sub solution($str) {
+ say qq{Input: \$str = "$str"};
+ say 'Output: ' . splitString($str);
+}
+
+say "Example 1:";
+solution("perl");
+
+say "\nExample 2:";
+solution("book");
+
+say "\nExample 3:";
+solution("good morning");
diff --git a/challenge-279/packy-anderson/python/ch-1.py b/challenge-279/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..f7fa18508d
--- /dev/null
+++ b/challenge-279/packy-anderson/python/ch-1.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+def sortLetters(letters, weights):
+ letterDict = dict(zip(weights, letters))
+ return (''.join([
+ letterDict[k] for k in sorted(letterDict.keys(), key=int)
+ ]))
+
+def comma_join(arr):
+ return ', '.join(map(lambda i: str(i), arr))
+
+def solution(letters, weights):
+ print(f"Input: @letters = ('{ ', '.join(letters)}')")
+ print(f" @weights = ({comma_join(weights)})")
+ print(f'Output: {sortLetters(letters, weights)}')
+
+print('Example 1:')
+solution(
+ ['R', 'E', 'P', 'L'], [3, 2, 1, 4]
+)
+
+print('\nExample 2:')
+solution(
+ ['A', 'U', 'R', 'K'], [2, 4, 1, 3]
+)
+
+print('\nExample 3:')
+solution(
+ ['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]
+)
+
+print('\nExample 4:')
+solution(
+ [ 'C', 'd', 'F', 'i', 'l', 'n', 'o', 'o', 's', 'u'],
+ [ 1, 4, 5, 8, 3, 10, 9, 2, 7, 6]
+)
diff --git a/challenge-279/packy-anderson/python/ch-2.py b/challenge-279/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..b0614bba56
--- /dev/null
+++ b/challenge-279/packy-anderson/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+vowels = ['a', 'e', 'i', 'o', 'u']
+
+def splitString(str):
+ return len([
+ v for v in list(str.lower()) if v in vowels
+ ]) % 2 == 0
+
+def solution(str):
+ print(f'Input: @str = "{str}"')
+ print(f'Output: {splitString(str)}')
+
+print('Example 1:')
+solution("perl")
+
+print('\nExample 2:')
+solution("book")
+
+print('\nExample 3:')
+solution("good morning")
diff --git a/challenge-279/packy-anderson/raku/ch-1.raku b/challenge-279/packy-anderson/raku/ch-1.raku
new file mode 100755
index 0000000000..cea6ae4dbb
--- /dev/null
+++ b/challenge-279/packy-anderson/raku/ch-1.raku
@@ -0,0 +1,34 @@
+#!/usr/bin/env raku
+use v6;
+
+sub sortLetters(@letters, @weights) {
+ my %letters = @weights Z=> @letters;
+ return %letters.sort(*.key.Int)>>.values.join(q{});
+}
+
+sub solution(@letters, @weights) {
+ say 'Input: @letters = (\'' ~ @letters.join('\', \'') ~ '\')';
+ say ' @weights = (' ~ @weights.join(', ') ~ ')';
+ say 'Output: ' ~ sortLetters(@letters, @weights);
+}
+
+say "Example 1:";
+solution(
+ ['R', 'E', 'P', 'L'], [3, 2, 1, 4]
+);
+
+say "\nExample 2:";
+solution(
+ ['A', 'U', 'R', 'K'], [2, 4, 1, 3]
+);
+
+say "\nExample 3:";
+solution(
+ ['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3]
+);
+
+say "\nExample 4:";
+solution(
+ [ 'C', 'd', 'F', 'i', 'l', 'n', 'o', 'o', 's', 'u'],
+ [ 1, 4, 5, 8, 3, 10, 9, 2, 7, 6]
+);
diff --git a/challenge-279/packy-anderson/raku/ch-2.raku b/challenge-279/packy-anderson/raku/ch-2.raku
new file mode 100755
index 0000000000..f01774d574
--- /dev/null
+++ b/challenge-279/packy-anderson/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+use v6;
+
+sub splitString($str) {
+ return $str.lc.comb(/<[aeiou]>/).elems % 2 == 0;
+}
+
+sub solution($str) {
+ say qq{Input: \$str = "$str"};
+ say 'Output: ' ~ splitString($str);
+}
+
+say "Example 1:";
+solution("perl");
+
+say "\nExample 2:";
+solution("book");
+
+say "\nExample 3:";
+solution("good morning");