diff options
26 files changed, 229 insertions, 38 deletions
diff --git a/challenge-342/mohammad-anwar/perl/ch-1.pl b/challenge-342/mohammad-anwar/perl/ch-1.pl new file mode 100644 index 0000000000..965d08d827 --- /dev/null +++ b/challenge-342/mohammad-anwar/perl/ch-1.pl @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +use v5.38; +use Test::More; + +my @examples = ( + ["a0b1c2", "0a1b2c" ], + ["abc12", "a1b2c" ], + ["0a2b1c3", "0a1b2c3"], + ["1a23", "" ], + ["ab123", "1a2b3" ], +); + +for (@examples) { + is(balance_string($_->[0]), $_->[1]); +} + +done_testing; + +sub balance_string { + my $s = shift; # Get the input string from arguments + my @d = sort grep /\d/, split //, $s; # Extract all digits and sort them + my @l = sort grep /\D/, split //, $s; # Extract all letters and sort them + + return "" if abs(@d - @l) > 1; # Return empty string if impossible + + @d > @l ? # If more digits than letters: + join "", # Join all elements into a string + map $d[$_] . ($l[$_] || ""), # For each index: digit + letter (or empty if no letter) + 0..$#d # Iterate through all digit indices + : # Else: + @l > @d ? # If more letters than digits: + join "", # Join all elements into a string + map $l[$_] . ($d[$_] || ""), # For each index: letter + digit (or empty if no digit) + 0..$#l # Iterate through all letter indices + : # Else (equal counts): + $d[0] lt $l[0] ? # If first digit < first letter lexicographically: + join "", # Join all elements into a string + map $d[$_] . $l[$_], # For each index: digit + letter + 0..$#d # Iterate through all indices (both arrays same size) + : # Else: + join "", # Join all elements into a string + map $l[$_] . $d[$_], # For each index: letter + digit + 0..$#d # Iterate through all indices (both arrays same size) +} diff --git a/challenge-342/mohammad-anwar/python/ch-1.py b/challenge-342/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..ab2ef75f81 --- /dev/null +++ b/challenge-342/mohammad-anwar/python/ch-1.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import re + +def balance_string(s): + # Extract all digits and sort them + d = sorted([c for c in s if c.isdigit()]) + # Extract all letters and sort them + l = sorted([c for c in s if c.isalpha()]) + + # Return empty string if impossible + if abs(len(d) - len(l)) > 1: + return "" + + # If more digits than letters: + if len(d) > len(l): + # Join all elements into a string + result = "" + # For each index: digit + letter (or empty if no letter) + for i in range(len(d)): + result += d[i] + (l[i] if i < len(l) else "") + return result + # Else if more letters than digits: + elif len(l) > len(d): + # Join all elements into a string + result = "" + # For each index: letter + digit (or empty if no digit) + for i in range(len(l)): + result += l[i] + (d[i] if i < len(d) else "") + return result + # Else (equal counts): + else: + # If first digit < first letter lexicographically: + if d[0] < l[0]: + # Join all elements into a string + result = "" + # For each index: digit + letter + for i in range(len(d)): + result += d[i] + l[i] + return result + # Else: + else: + # Join all elements into a string + result = "" + # For each index: letter + digit + for i in range(len(d)): + result += l[i] + d[i] + return result + +examples = [ + ["a0b1c2", "0a1b2c" ], + ["abc12", "a1b2c" ], + ["0a2b1c3", "0a1b2c3"], + ["1a23", "" ], + ["ab123", "1a2b3" ], +] + +for example in examples: + input_str, expected = example + result = balance_string(input_str) + print(f"Pass: {result == expected}") diff --git a/challenge-342/mohammad-anwar/raku/ch-1.raku b/challenge-342/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..d4b7851deb --- /dev/null +++ b/challenge-342/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,66 @@ +#!/usr/bin/env raku + +my @examples = ( + ["a0b1c2", "0a1b2c" ], + ["abc12", "a1b2c" ], + ["0a2b1c3", "0a1b2c3"], + ["1a23", "" ], + ["ab123", "1a2b3" ], +); + +for @examples -> @example { + my ($input, $expected) = @example; + my $result = balance-string($input); + say "Pass: {$result eq $expected}"; +} + +sub balance-string(Str $s) { + # Extract all digits and sort them + my @d = $s.comb.grep({ /<digit>/ }).sort; + # Extract all letters and sort them + my @l = $s.comb.grep({ /<alpha>/ }).sort; + + # Return empty string if impossible + return "" if abs(@d.elems - @l.elems) > 1; + + # If more digits than letters: + if @d.elems > @l.elems { + # Join all elements into a string + return join "", + # For each index: digit + letter (or empty if no letter) + map { @d[$_] ~ (@l[$_] // "") }, + # Iterate through all digit indices + 0..^@d.elems; + } + # Else if more letters than digits: + elsif @l.elems > @d.elems { + # Join all elements into a string + return join "", + # For each index: letter + digit (or empty if no digit) + map { @l[$_] ~ (@d[$_] // "") }, + # Iterate through all letter indices + 0..^@l.elems; + } + # Else (equal counts): + else { + # If first digit < first letter lexicographically: + if @d[0] lt @l[0] { + # Join all elements into a string + return join "", + # For each index: digit + letter + map { @d[$_] ~ @l[$_] }, + # Iterate through all indices (both arrays same size) + 0..^@d.elems; + } + # Else: + else { + # Join all elements into a string + return join "", + # For each index: letter + digit + map { @l[$_] ~ @d[$_] }, + # Iterate through all indices (both arrays same size) + 0..^@d.elems; + } + } +} + diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 41925471b4..1993667a84 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -78,6 +78,20 @@ "data" : [ [ "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ], + "id" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar" + }, + { + "data" : [ + [ + "Perl", 2 ], [ @@ -170,6 +184,11 @@ "y" : 2 }, { + "drilldown" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar", + "y" : 2 + }, + { "drilldown" : "Peter Campbell Smith", "name" : "Peter Campbell Smith", "y" : 3 @@ -189,7 +208,7 @@ } ], "subtitle" : { - "text" : "[Champions: 10] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 11] Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge - 342" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 326faaa80e..55b7afaf9a 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index be95666a06..4e48baf468 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index bce14f0b5f..dde45d3a8a 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 2c460eac54..3de9528a85 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index f1a4090528..1ddea90af6 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 917b67377b..fbd0e12357 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-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index c42729a75d..69a043b524 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 14 + 15 ], [ "Raku", - 7 + 8 ], [ "Blog", @@ -745,7 +745,7 @@ { "drilldown" : "342", "name" : "342", - "y" : 23 + "y" : 25 }, { "drilldown" : "341", @@ -947,7 +947,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 731971833f..2b7c541279 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,11 +10,11 @@ "data" : [ [ "Perl", - 17610 + 17611 ], [ "Raku", - 9783 + 9784 ], [ "Blog", @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-10-06 18:40:03 GMT" + "text" : "Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 5ebb50c7d8..773f838094 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -480,11 +480,11 @@ "data" : [ [ "Perl", - 174 + 175 ], [ "Raku", - 107 + 108 ], [ "Blog", @@ -947,7 +947,7 @@ { "drilldown" : "Mohammad Sajid Anwar", "name" : "31: Mohammad Sajid Anwar", - "y" : 724 + "y" : 728 }, { "drilldown" : "Robert Ransbottom", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 5f3b4db947..65043ed5f9 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 940132f31b..b686b2b168 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 04fbd2ad65..1198bcdf01 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 b51e4708e2..5c22af85b8 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -28,7 +28,7 @@ 0, 0, 1, - 174, + 175, 0, 0, 40, @@ -63,7 +63,7 @@ 2, 0, 0, - 107, + 108, 1, 10, 40, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 007e32a8a4..4e53145615 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 f5bf6b1dc0..8b5121f6b6 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 0718b54288..97dd341241 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 3550e8f187..4a893a4844 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 28] Last updated at 2025-10-06 19:14:03 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 da5faf42e6..73111fefb6 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 9cb9c6a7fe..50e0e55505 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 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 1a330a3172..c21d2ab80c 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-10-06 18:40:03 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index 5a65e9fb1b..2b94cca2ff 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -208,7 +208,7 @@ 0, 0, 1, - 108, + 109, 0, 0, 20, @@ -541,7 +541,7 @@ 1, 0, 0, - 66, + 67, 1, 5, 20, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-10-06 18:40:03 GMT" + "text" : "[Champions: 328] Last updated at 2025-10-06 19:14:03 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 23fb045f72..3f0ca7d542 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 1833 + 1834 ], [ "Raku", - 907 + 908 ], [ "Blog", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 3464 + "y" : 3466 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 18:40:03 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-06 19:14:03 GMT" }, "title" : { "text" : "The Weekly Challenge Language" |
