diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-05 20:07:20 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-05 20:07:20 +0100 |
| commit | a531699beeacf4ea3bc9aec6a30a9ffc6f9d0414 (patch) | |
| tree | b8d4d514bed06efd9944c090673f6f4c78e2a4c8 | |
| parent | c65be24cab402201d79f2996efd8ecfc2b68eb7e (diff) | |
| download | perlweeklychallenge-club-a531699beeacf4ea3bc9aec6a30a9ffc6f9d0414.tar.gz perlweeklychallenge-club-a531699beeacf4ea3bc9aec6a30a9ffc6f9d0414.tar.bz2 perlweeklychallenge-club-a531699beeacf4ea3bc9aec6a30a9ffc6f9d0414.zip | |
- Added solutions by Mark Anderson.
- Added solutions by Packy Anderson.
- Added solutions by Robert Ransbottom.
25 files changed, 247 insertions, 62 deletions
diff --git a/challenge-328/0rir/raku/ch-1.raku b/challenge-328/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..fc78ba89b1 --- /dev/null +++ b/challenge-328/0rir/raku/ch-1.raku @@ -0,0 +1,87 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +328-Task 1: Replace all ? +Submitted by: Mohammad Sajid Anwar +You are given a string containing only lower case English letters and ?. +Write a script to replace all ? in the given string so that the string doesn’t contain consecutive repeating characters. +Example 1 +Input: $str = "a?z" +Output: "abz" +There can be many strings, one of them is "abz". +The choices are 'a' to 'z' but we can't use either 'a' or 'z' to replace the '?'. +Example 2 +Input: $str = "pe?k" +Output: "peak" +Example 3 +Input: $str = "gra?te" +Output: "grabte" +=end comment + +my @Test = + "", "", + "?", "a", + 'z', "z", + "a?", "ab", + "?a", "ba", + "??", "ab", + "??a", "aba", + "b??", "bab", + "gra?te", "grabte", + "g?a?te", "gbabte", + "g???te", "gabate", + "g????e", "gababe", + "g?????", "gababa", + 'xy', 'xy', + "xyz", "xyz", + "azc", "azc", + "pe?k", "peak", + "??????", "ababab", + "g?a?te", "gbabte", +; + +plan +@Test ÷ 2; + +# Here we follow a pattern suggested by the examples: replace with the +# alphabetically first char that fits. + +constant \fix-me = '?'; # Char value needing replacement. +constant \first-choice = 'a'; # First choice for substitutions. +constant \filler = '!'; # Out of band value for stand-ins. + +sub alter( Any:D $q-mark is rw, :$prefix = filler, :$suffix = filler -->Nil) { + $q-mark = first-choice; + quietly ++$q-mark while $q-mark eq any($prefix, $suffix); + return; +} + +multi task( Str:D $a where *.chars == 0 -->Str) { '' } +multi task( Str:D $a where *.chars == 1 -->Str) { + $a eq fix-me ?? first-choice !! $a ; +} +multi task( Str:D $a where *.chars ≥ 1 --> Str) { + my @s = $a.comb; + + if @s[0] eq fix-me { alter @s[0], :suffix(@s[1]) } + + for 1..(@s.end) -> \i { + next if @s[i] ne fix-me; + alter @s[i], :prefix(@s[i-1]), :suffix( @s[i+1]); + } + + if @s[*.end] eq fix-me { alter @s[*.end], :prefix(@s[*.end-1]) } + @s.join; +} + +for @Test -> $in, $exp, { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()"; +} + +done-testing; + +my $str = "??????a?g?r???a?te?"; + +say qq{\nInput: \$str = "$str"\nOutput: "}, task($str), '"'; diff --git a/challenge-328/0rir/raku/ch-2.raku b/challenge-328/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..446baf13d2 --- /dev/null +++ b/challenge-328/0rir/raku/ch-2.raku @@ -0,0 +1,60 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +328-Task 2: Good 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 good string of the given string. A string is called good string if it doesn’t have two adjacent same characters, one in upper case and other is lower case. +UPDATE [2025-07-01]: Just to be explicit, you can only remove pair if they are same characters, one in lower case and other in upper case, order is not important. +Example 1 +Input: $str = "WeEeekly" +Output: "Weekly" +We can remove either, "eE" or "Ee" to make it good. +Example 2 +Input: $str = "abBAdD" +Output: "" +We remove "bB" first: "aAdD" +Then we remove "aA": "dD" +Finally remove "dD". +Example 3 +Input: $str = "abc" +Output: "abc" +=end comment + +my @Test = + # $in $exp + "WeEeekly", "Weekly", + "abBAdD", "", + "abc", "abc", + 'abcdefghHGFEDCBa', 'aa', + 'bcdefghHGFEDCBa', 'a', + 'abcdefghHGFEDCB', 'a', + "XxabBAdD", '', + "XxnabBAmdD", 'nm', + "AaXxnabBAmdDzZ", 'nm', +; +plan +@Test ÷ 2; + +constant XCASE = 32; + +sub task( Str $a is copy --> Str) { + my $unchanged; + repeat { + $unchanged = $a; + $a ~~ s:g/ (<:L>)(<:L>) <?{ XCASE == abs($0.ord-$1.ord)}>//; + } until $a eq $unchanged; + $a; +} + +for @Test -> $in, $exp { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()"; +} +done-testing; + +my $str = "AaaAaBbbbBCcc"; + +say qq{\nInput: \$str = "$str"\nOutput: "}, task( $str), '"'; + diff --git a/stats/pwc-current.json b/stats/pwc-current.json index ae9dcd3535..58fd7dfa15 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -171,6 +171,24 @@ 2 ], [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Packy Anderson", + "name" : "Packy Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Blog", 1 ] @@ -193,6 +211,16 @@ [ "Raku", 2 + ] + ], + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom" + }, + { + "data" : [ + [ + "Raku", + 2 ], [ "Blog", @@ -357,6 +385,11 @@ "y" : 2 }, { + "drilldown" : "Packy Anderson", + "name" : "Packy Anderson", + "y" : 5 + }, + { "drilldown" : "Peter Campbell Smith", "name" : "Peter Campbell Smith", "y" : 3 @@ -367,6 +400,11 @@ "y" : 2 }, { + "drilldown" : "Robert Ransbottom", + "name" : "Robert Ransbottom", + "y" : 2 + }, + { "drilldown" : "Simon Proctor", "name" : "Simon Proctor", "y" : 3 @@ -401,7 +439,7 @@ } ], "subtitle" : { - "text" : "[Champions: 22] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 24] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge - 328" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 0a609c7681..1af9c3d0e6 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index de3ac91986..eac8c66ee5 100644 --- a/stats/pwc-language-breakdown-2020.json +++ b/stats/pwc-language-breakdown-2020.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 73bcbeaec6..4f9c8a3f77 100644 --- a/stats/pwc-language-breakdown-2021.json +++ b/stats/pwc-language-breakdown-2021.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 091485b145..d6a24d02c6 100644 --- a/stats/pwc-language-breakdown-2022.json +++ b/stats/pwc-language-breakdown-2022.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index b151dc6658..a4d054c36d 100644 --- a/stats/pwc-language-breakdown-2023.json +++ b/stats/pwc-language-breakdown-2023.json @@ -1200,7 +1200,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 66f30d02cd..42cd07c071 100644 --- a/stats/pwc-language-breakdown-2024.json +++ b/stats/pwc-language-breakdown-2024.json @@ -1246,7 +1246,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 905ba39808..8beca38a3d 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 34 + 36 ], [ "Raku", - 14 + 18 ], [ "Blog", - 14 + 15 ] ], "id" : "328", @@ -493,7 +493,7 @@ { "drilldown" : "328", "name" : "328", - "y" : 62 + "y" : 69 }, { "drilldown" : "327", @@ -625,7 +625,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 489bfeb870..f8fecc18db 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,15 +10,15 @@ "data" : [ [ "Perl", - 16944 + 16946 ], [ "Raku", - 9425 + 9429 ], [ "Blog", - 6048 + 6049 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 90f45c5e21..6dc3b7a27f 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -424,33 +424,33 @@ "data" : [ [ "Perl", - 396 + 160 + ], + [ + "Raku", + 160 ], [ "Blog", - 1 + 81 ] ], - "id" : "Duncan C. White", - "name" : "Duncan C. White" + "id" : "Packy Anderson", + "name" : "Packy Anderson" }, { "data" : [ [ "Perl", - 158 - ], - [ - "Raku", - 158 + 396 ], [ "Blog", - 80 + 1 ] ], - "id" : "Packy Anderson", - "name" : "Packy Anderson" + "id" : "Duncan C. White", + "name" : "Duncan C. White" }, { "data" : [ @@ -516,7 +516,7 @@ "data" : [ [ "Raku", - 324 + 326 ], [ "Blog", @@ -925,14 +925,14 @@ "y" : 804 }, { - "drilldown" : "Duncan C. White", - "name" : "27: Duncan C. White", - "y" : 794 + "drilldown" : "Packy Anderson", + "name" : "27: Packy Anderson", + "y" : 802 }, { - "drilldown" : "Packy Anderson", - "name" : "28: Packy Anderson", - "y" : 792 + "drilldown" : "Duncan C. White", + "name" : "28: Duncan C. White", + "y" : 794 }, { "drilldown" : "Niels van Dijke", @@ -957,7 +957,7 @@ { "drilldown" : "Robert Ransbottom", "name" : "33: Robert Ransbottom", - "y" : 652 + "y" : 656 }, { "drilldown" : "Wanderdoc", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 5607346aff..63f9dd4a3d 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-121-150.json b/stats/pwc-summary-121-150.json index a366c193cf..523ea5869c 100644 --- a/stats/pwc-summary-121-150.json +++ b/stats/pwc-summary-121-150.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-151-180.json b/stats/pwc-summary-151-180.json index 8fb0f2e838..d2aeb23f59 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-181-210.json b/stats/pwc-summary-181-210.json index 699604dc69..7dc6ba2650 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-211-240.json b/stats/pwc-summary-211-240.json index 3c6cd8932b..94de7bd061 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -14,7 +14,7 @@ 0, 0, 8, - 158, + 160, 18, 594, 3, @@ -49,7 +49,7 @@ 0, 28, 0, - 158, + 160, 0, 0, 0, @@ -84,7 +84,7 @@ 0, 0, 0, - 80, + 81, 0, 0, 1, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-241-270.json b/stats/pwc-summary-241-270.json index aad4e9c446..3fff027954 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -64,7 +64,7 @@ 131, 6, 3, - 324, + 326, 0, 575, 113, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-271-300.json b/stats/pwc-summary-271-300.json index d3d16823e1..d2255b417a 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-301-330.json b/stats/pwc-summary-301-330.json index b401383afe..7c516d67e8 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -100,7 +100,7 @@ } ], "subtitle" : { - "text" : "[Champions: 25] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 25] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-31-60.json b/stats/pwc-summary-31-60.json index 66f8dff26d..913880c948 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-61-90.json b/stats/pwc-summary-61-90.json index 28d1f4afce..cd09209f64 100644 --- a/stats/pwc-summary-61-90.json +++ b/stats/pwc-summary-61-90.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-91-120.json b/stats/pwc-summary-91-120.json index a7f798a340..9bd47362f7 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 30] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index c585b8d853..c6627da2a0 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -224,7 +224,7 @@ 0, 0, 5, - 80, + 81, 9, 297, 2, @@ -554,7 +554,7 @@ 0, 20, 0, - 80, + 81, 0, 0, 0, @@ -599,7 +599,7 @@ 84, 3, 2, - 166, + 167, 0, 298, 57, @@ -884,7 +884,7 @@ 0, 0, 0, - 80, + 81, 0, 0, 1, @@ -1000,7 +1000,7 @@ } ], "subtitle" : { - "text" : "[Champions: 325] Last updated at 2025-07-05 09:56:20 GMT" + "text" : "[Champions: 325] Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-yearly-language-summary.json b/stats/pwc-yearly-language-summary.json index 40504b9d1d..edc109cc49 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 1177 + 1179 ], [ "Raku", - 559 + 563 ], [ "Blog", - 471 + 472 ] ], "id" : "2025", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 2207 + "y" : 2214 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 09:56:20 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-07-05 19:07:05 GMT" }, "title" : { "text" : "The Weekly Challenge Language" |
