diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-10 09:37:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 09:37:28 +0100 |
| commit | 77ad44d950503fda17d4d9feffc234b24f918bb9 (patch) | |
| tree | 007efbc93f45ad560aabe28114b353923153c9e5 | |
| parent | c80c3ca2f11220d15fe98423b1a03ac2b61a4ba3 (diff) | |
| parent | 9bd6c3bba5908f94c400796e153b0e639fbfd69f (diff) | |
| download | perlweeklychallenge-club-77ad44d950503fda17d4d9feffc234b24f918bb9.tar.gz perlweeklychallenge-club-77ad44d950503fda17d4d9feffc234b24f918bb9.tar.bz2 perlweeklychallenge-club-77ad44d950503fda17d4d9feffc234b24f918bb9.zip | |
Merge pull request #12318 from 0rir/work
329
| -rw-r--r-- | challenge-329/0rir/raku/ch-1.raku | 47 | ||||
| -rw-r--r-- | challenge-329/0rir/raku/ch-2.raku | 72 |
2 files changed, 119 insertions, 0 deletions
diff --git a/challenge-329/0rir/raku/ch-1.raku b/challenge-329/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..6852e0c4ba --- /dev/null +++ b/challenge-329/0rir/raku/ch-1.raku @@ -0,0 +1,47 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 1: Counter Integers Submitted by: Mohammad Sajid Anwar +You are given a string containing only lower case English letters and digits. + +Write a script to replace every non-digit character with a space and then return all the distinct integers left. + +Example 1 +Input: $str = "the1weekly2challenge2" +Output: 1, 2 + +2 is appeared twice, so we count it one only. + +Example 2 +Input: $str = "go21od1lu5c7k" +Output: 21, 1, 5, 7 + +Example 3 +Input: $str = "4p3e2r1l" +Output: 4, 3, 2, 1 +=end comment + +my @Test = + # in exp + "the1weekly2challenge2", (1, 2,), + "go21od1lu5c7k", (21, 1, 5, 7,), + "4p3e2r1l", (4, 3, 2, 1,), + "raku", (), +; +plan +@Test ÷ 2; + +sub task( $a --> Array) { + ( ($a ~~ m:g/\d+/ )».Str).unique.Array +} + +for @Test -> $in, @exp { + is task( $in), @exp, "{@exp // @exp.^name()} <- $in.raku()"; +} +done-testing; + +my $str = "pqwo48957u10qt7430qr10uo105973hjf5973hj"; + +say qq/\nInput: \$str = "$str"\nOutput: "&task($str).join(', ')"\n/; diff --git a/challenge-329/0rir/raku/ch-2.raku b/challenge-329/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..68940e6f47 --- /dev/null +++ b/challenge-329/0rir/raku/ch-2.raku @@ -0,0 +1,72 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +329-2: Nice String +Submitted by: Mohammad Sajid Anwar +You are given a string made up of lower and upper case English letters only. + +Write a script to return the longest substring of the give string which is nice. A string is nice if, for every letter of the alphabet that the string contains, it appears both in uppercase and lowercase. + +Example 1 +Input: $str = "YaaAho" +Output: "aaA" + +Example 2 +Input: $str = "cC" +Output: "cC" + +Example 3 +Input: $str = "A" +Output: "" +=end comment + +my @Test = + # in exp + "YaaAho", "aaA", + "cC", "cC", + "A", "", + "", "", +; +plan 2 +@Test ÷ 2; + +# First and rest of a string as Anys in an Array +multi head-tail( Str:D $s is copy --> Array) { + my Str $head = $s.substr(0,1); + $s.substr-rw(0, 1) = ""; + return [$head, $s]; +} + +# Assume there is an other-case and return it. +sub oc( Str:D $char --> Str:D) { + $char eq $char.uc ?? $char.lc !! $char.uc +} + + +# Is it an empty Str or an empty Str of Letters? +#multi task( '') { die 'empty string' } + +multi task( Str $a -->Str:D) { + my Str $ret = ''; + my Str $s = $a; + + while $s.chars > 0 { + my Str $h; + ($h, $s) = $s.&head-tail; + $ret ~= $h if $ret.contains($h, :i) or $s.contains($h.&oc); + } + $ret; +} + +is oc( 'a'), 'A', 'other case'; +is oc( 'A'), 'a', 'other case'; + +for @Test -> $in, $exp { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()"; +} +done-testing; + +my $str = "slifdhLasLKFGA"; +say qq{\nInput: \$str = "$str"\nOutput: "}, task( $str), '"'; |
