diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-19 23:49:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-19 23:49:18 +0100 |
| commit | 2ff172277cb38482f4c982857a0d18596d7d6d1e (patch) | |
| tree | b340e29825f6cdd3321353256c8c18e2a9b657a7 | |
| parent | f68d83f6adeb3dd88d3763bc5272a8e28c3b5e6e (diff) | |
| parent | 58663c20f1ba710ea67e5de1ee6330173338c255 (diff) | |
| download | perlweeklychallenge-club-2ff172277cb38482f4c982857a0d18596d7d6d1e.tar.gz perlweeklychallenge-club-2ff172277cb38482f4c982857a0d18596d7d6d1e.tar.bz2 perlweeklychallenge-club-2ff172277cb38482f4c982857a0d18596d7d6d1e.zip | |
Merge pull request #12369 from packy/master
Challenge 330 solutions by Packy Anderson
| -rw-r--r-- | challenge-330/packy-anderson/README.md | 2 | ||||
| -rw-r--r-- | challenge-330/packy-anderson/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/elixir/ch-1.exs | 23 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/elixir/ch-2.exs | 28 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/perl/ch-1.pl | 21 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/perl/ch-2.pl | 24 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/python/ch-1.py | 22 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/python/ch-2.py | 22 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/raku/ch-1.raku | 21 | ||||
| -rwxr-xr-x | challenge-330/packy-anderson/raku/ch-2.raku | 24 |
10 files changed, 187 insertions, 1 deletions
diff --git a/challenge-330/packy-anderson/README.md b/challenge-330/packy-anderson/README.md index 8c6ccb3256..c3bfc77311 100644 --- a/challenge-330/packy-anderson/README.md +++ b/challenge-330/packy-anderson/README.md @@ -23,4 +23,4 @@ ## Blog Post -[Perl Weekly Challenge: It MUST be nice!](https://packy.dardan.com/b/Xd) +[Perl Weekly Challenge: [TITLE OF THE POST]](https://packy.dardan.com/b/Yf) diff --git a/challenge-330/packy-anderson/blog.txt b/challenge-330/packy-anderson/blog.txt new file mode 100644 index 0000000000..24d812b2da --- /dev/null +++ b/challenge-330/packy-anderson/blog.txt @@ -0,0 +1 @@ +https://packy.dardan.com/b/Yf
\ No newline at end of file diff --git a/challenge-330/packy-anderson/elixir/ch-1.exs b/challenge-330/packy-anderson/elixir/ch-1.exs new file mode 100755 index 0000000000..72052fcffc --- /dev/null +++ b/challenge-330/packy-anderson/elixir/ch-1.exs @@ -0,0 +1,23 @@ +#!/usr/bin/env elixir + +defmodule PWC do + def clear_digits(str) do + if Regex.match?(~r/\D\d/, str), + do: clear_digits(Regex.replace(~r/\D\d/,str,"")), + else: str + end + + def solution(str) do + IO.puts("Input: $str = \"#{str}\"") + IO.puts("Output: \"#{clear_digits(str)}\"") + end +end + +IO.puts("Example 1:") +PWC.solution("cab12") + +IO.puts("\nExample 2:") +PWC.solution("xy99") + +IO.puts("\nExample 3:") +PWC.solution("pa1erl") diff --git a/challenge-330/packy-anderson/elixir/ch-2.exs b/challenge-330/packy-anderson/elixir/ch-2.exs new file mode 100755 index 0000000000..929dc4e89a --- /dev/null +++ b/challenge-330/packy-anderson/elixir/ch-2.exs @@ -0,0 +1,28 @@ +#!/usr/bin/env elixir + +defmodule PWC do + def title_capital(str) do + str + |> String.split # separated by a SINGLE space + |> Enum.map(fn w -> + if String.length(w) > 2, + do: String.capitalize(w), + else: String.downcase(w) + end) + |> Enum.join(" ") + end + + def solution(str) do + IO.puts("Input: $str = \"#{str}\"") + IO.puts("Output: \"#{title_capital(str)}\"") + end +end + +IO.puts("Example 1:") +PWC.solution("PERL IS gREAT") + +IO.puts("\nExample 2:") +PWC.solution("THE weekly challenge") + +IO.puts("\nExample 3:") +PWC.solution("YoU ARE A stAR") diff --git a/challenge-330/packy-anderson/perl/ch-1.pl b/challenge-330/packy-anderson/perl/ch-1.pl new file mode 100755 index 0000000000..989700eb91 --- /dev/null +++ b/challenge-330/packy-anderson/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +use v5.40; + +sub clearDigits($str) { + while ($str =~ s/\D\d//) {} + return $str; +} + +sub solution($str) { + say qq/Input: \$str = "$str"/; + say qq/Output: "@{[clearDigits($str)]}"/; +} + +say "Example 1:"; +solution("cab12"); + +say "\nExample 2:"; +solution("xy99"); + +say "\nExample 3:"; +solution("pa1erl");
\ No newline at end of file diff --git a/challenge-330/packy-anderson/perl/ch-2.pl b/challenge-330/packy-anderson/perl/ch-2.pl new file mode 100755 index 0000000000..6a9922d0e7 --- /dev/null +++ b/challenge-330/packy-anderson/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +use v5.40; + +sub titleCapital($str) { + my @out = split " ", lc($str); # separated by a SINGLE space + foreach my $word ( @out ) { # mods to $word change @out + $word = ucfirst($word) if length($word) > 2; + } + return join(" ", @out); +} + +sub solution($str) { + say qq/Input: \$str = "$str"/; + say qq/Output: "@{[titleCapital($str)]}"/; +} + +say "Example 1:"; +solution("PERL IS gREAT"); + +say "\nExample 2:"; +solution("THE weekly challenge"); + +say "\nExample 3:"; +solution("YoU ARE A stAR"); diff --git a/challenge-330/packy-anderson/python/ch-1.py b/challenge-330/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..41f43c7880 --- /dev/null +++ b/challenge-330/packy-anderson/python/ch-1.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import re +cd = re.compile(r'\D\d') + +def clear_digits(strVal): + if cd.search(strVal): + strVal = clear_digits(cd.sub("", strVal)) + return strVal + +def solution(strVal): + print(f'Input: $str = "{strVal}"') + print(f'Output: "{clear_digits(strVal)}"') + +print('Example 1:') +solution("cab12") + +print('\nExample 2:') +solution("xy99") + +print('\nExample 3:') +solution("pa1erl") diff --git a/challenge-330/packy-anderson/python/ch-2.py b/challenge-330/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..d03e7342be --- /dev/null +++ b/challenge-330/packy-anderson/python/ch-2.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +def title_capital(strVal): + return " ".join( + [ + w.title() if len(w) > 2 else w + for w in strVal.lower().split() + ] + ) + +def solution(strVal): + print(f'Input: $str = "{strVal}"') + print(f'Output: "{title_capital(strVal)}"') + +print('Example 1:') +solution("PERL IS gREAT") + +print('\nExample 2:') +solution("THE weekly challenge") + +print('\nExample 3:') +solution("YoU ARE A stAR") diff --git a/challenge-330/packy-anderson/raku/ch-1.raku b/challenge-330/packy-anderson/raku/ch-1.raku new file mode 100755 index 0000000000..afaef7514a --- /dev/null +++ b/challenge-330/packy-anderson/raku/ch-1.raku @@ -0,0 +1,21 @@ +#!/usr/bin/env raku +use v6; + +sub clearDigits($str is copy) { + while ($str ~~ s/\D\d//) {} + return $str; +} + +sub solution($str) { + say qq/Input: \$str = "$str"/; + say qq/Output: "{clearDigits($str)}"/; +} + +say "Example 1:"; +solution("cab12"); + +say "\nExample 2:"; +solution("xy99"); + +say "\nExample 3:"; +solution("pa1erl"); diff --git a/challenge-330/packy-anderson/raku/ch-2.raku b/challenge-330/packy-anderson/raku/ch-2.raku new file mode 100755 index 0000000000..e4cec1e26c --- /dev/null +++ b/challenge-330/packy-anderson/raku/ch-2.raku @@ -0,0 +1,24 @@ +#!/usr/bin/env raku +use v6; + +sub titleCapital($str) { + my @out = $str.lc.split(" "); # separated by a SINGLE space + for @out <-> $word { # <-> makes mods to $word change @out + $word = $word.tc if $word.chars > 2; + } + return @out.join(" "); +} + +sub solution($str) { + say qq/Input: \$str = "$str"/; + say qq/Output: "{titleCapital($str)}"/; +} + +say "Example 1:"; +solution("PERL IS gREAT"); + +say "\nExample 2:"; +solution("THE weekly challenge"); + +say "\nExample 3:"; +solution("YoU ARE A stAR"); |
