From 2afc3dadbb61378fc86bd2fda57871625dbcb8dd Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 2 Nov 2025 22:32:36 +1000 Subject: sgreen solutions to challenge 345 --- challenge-345/sgreen/README.md | 4 ++-- challenge-345/sgreen/blog.txt | 1 + challenge-345/sgreen/perl/ch-1.pl | 34 ++++++++++++++++++++++++++++++ challenge-345/sgreen/perl/ch-2.pl | 35 +++++++++++++++++++++++++++++++ challenge-345/sgreen/python/ch-1.py | 42 +++++++++++++++++++++++++++++++++++++ challenge-345/sgreen/python/ch-2.py | 34 ++++++++++++++++++++++++++++++ challenge-345/sgreen/python/test.py | 26 +++++++++++++++++++++++ 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 challenge-345/sgreen/blog.txt create mode 100755 challenge-345/sgreen/perl/ch-1.pl create mode 100755 challenge-345/sgreen/perl/ch-2.pl create mode 100755 challenge-345/sgreen/python/ch-1.py create mode 100755 challenge-345/sgreen/python/ch-2.py create mode 100755 challenge-345/sgreen/python/test.py diff --git a/challenge-345/sgreen/README.md b/challenge-345/sgreen/README.md index 41cfdac46a..38d33ba9fb 100644 --- a/challenge-345/sgreen/README.md +++ b/challenge-345/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 344 +# The Weekly Challenge 345 -Blog: [The one about arrays](https://dev.to/simongreennet/weekly-challenge-the-one-about-arrays-1h8k) +Blog: [Peak Visitors](https://dev.to/simongreennet/weekly-challenge-peak-visitors-3lei) diff --git a/challenge-345/sgreen/blog.txt b/challenge-345/sgreen/blog.txt new file mode 100644 index 0000000000..47daf16457 --- /dev/null +++ b/challenge-345/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-peak-visitors-3lei \ No newline at end of file diff --git a/challenge-345/sgreen/perl/ch-1.pl b/challenge-345/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..40cf5bfa68 --- /dev/null +++ b/challenge-345/sgreen/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +sub main (@ints) { + my @peaks = (); + + # Check first element + if ( $ints[0] > $ints[1] ) { + push @peaks, 0; + } + + # Check middle elements + foreach my $pos ( 1 .. $#ints - 1 ) { + if ( $ints[$pos] > $ints[ $pos - 1 ] + and $ints[$pos] > $ints[ $pos + 1 ] ) + { + push @peaks, $pos; + } + } + + # Check last element + if ( $ints[-1] > $ints[-2] ) { + push @peaks, $#ints; + } + + # Print list of peak positions + say "(", join( ", ", @peaks ), ")"; +} + +main(@ARGV); diff --git a/challenge-345/sgreen/perl/ch-2.pl b/challenge-345/sgreen/perl/ch-2.pl new file mode 100755 index 0000000000..8836c90622 --- /dev/null +++ b/challenge-345/sgreen/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +sub main (@ints) { + my @seen = (); + my @ans = (); + my $neg_count = 0; + + foreach my $i (@ints) { + if ( $i > 0 ) { + unshift @seen, $i; + $neg_count = 0; + } + elsif ( $i == -1 ) { + if ( $neg_count < @seen ) { + push @ans, $seen[$neg_count]; + } + else { + push @ans, -1; + } + $neg_count++; + } + else { + die "Input integers must be positive or -1.\n"; + } + } + + say "(", join( ", ", @ans ), ")"; +} + +main(@ARGV); diff --git a/challenge-345/sgreen/python/ch-1.py b/challenge-345/sgreen/python/ch-1.py new file mode 100755 index 0000000000..6211e45304 --- /dev/null +++ b/challenge-345/sgreen/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import sys + + +def peak_positions(ints: list[int]) -> list[int]: + """Return list of positions of peaks in the input list. + + Args: + ints (list[int]): List of integers to analyze. + + Returns: + list[int]: List of indices where peaks are located. + """ + peaks = [] + + # Check first element + if ints[0] > ints[1]: + peaks.append(0) + + # Check middle elements + for pos in range(1, len(ints) - 1): + if ints[pos] > ints[pos - 1] and ints[pos] > ints[pos + 1]: + peaks.append(pos) + + # Check last element + if ints[-1] > ints[-2]: + peaks.append(len(ints) - 1) + + # Return list of peak positions + return peaks + + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = peak_positions(array) + print('(' + ', '.join(map(str, result)) + ')') + + +if __name__ == '__main__': + main() diff --git a/challenge-345/sgreen/python/ch-2.py b/challenge-345/sgreen/python/ch-2.py new file mode 100755 index 0000000000..93797c9ee8 --- /dev/null +++ b/challenge-345/sgreen/python/ch-2.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import sys + + +def last_visitor(ints: list[int]) -> list[int]: + seen = [] + ans = [] + neg_count = 0 + + for i in ints: + if i > 0: + seen.insert(0, i) + neg_count = 0 + elif i == -1: + if neg_count < len(seen): + ans.append(seen[neg_count]) + else: + ans.append(-1) + neg_count += 1 + else: + raise ValueError("Input integers must be positive or -1.") + + return ans + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = last_visitor(array) + print('(' + ', '.join(map(str, result)) + ')') + + +if __name__ == '__main__': + main() diff --git a/challenge-345/sgreen/python/test.py b/challenge-345/sgreen/python/test.py new file mode 100755 index 0000000000..bbf9c70167 --- /dev/null +++ b/challenge-345/sgreen/python/test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import unittest +ch_1 = __import__('ch-1') +ch_2 = __import__('ch-2') + + +class TestClass(unittest.TestCase): + def test_ch_1(self): + self.assertEqual(ch_1.peak_positions([1, 3, 2]), [1]) + self.assertEqual(ch_1.peak_positions([2, 4, 6, 5, 3]), [2]) + self.assertEqual(ch_1.peak_positions([1, 2, 3, 2, 4, 1]), [2, 4]) + self.assertEqual(ch_1.peak_positions([5, 3, 1]), [0]) + self.assertEqual(ch_1.peak_positions([1, 5, 1, 5, 1, 5, 1]), [1, 3, 5]) + self.assertEqual(ch_1.peak_positions([1, 2, 3, 4, 4]), []) + + def test_ch_2(self): + self.assertEqual(ch_2.last_visitor([5, -1, -1]), [5, -1]) + self.assertEqual(ch_2.last_visitor([3, 7, -1, -1, -1]), [7, 3, -1]) + self.assertEqual(ch_2.last_visitor([2, -1, 4, -1, -1]), [2, 4, 2]) + self.assertEqual(ch_2.last_visitor([10, 20, -1, 30, -1, -1]), [20, 30, 20]) + self.assertEqual(ch_2.last_visitor([-1, -1, 5, -1]), [-1, -1, 5]) + + +if __name__ == '__main__': + unittest.main() -- cgit From 9490291b8cf7bf2c950c7ffe532f220cc55a111c Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Sun, 2 Nov 2025 13:11:51 +0000 Subject: - Added solutions by Simon Green. --- stats/pwc-current.json | 21 ++++++++++++++++++++- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 8 ++++---- stats/pwc-language-breakdown-summary.json | 6 +++--- stats/pwc-leaders.json | 8 ++++---- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 2 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 6 +++--- stats/pwc-summary-301-330.json | 2 +- stats/pwc-summary-31-60.json | 4 ++-- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 6 +++--- stats/pwc-yearly-language-summary.json | 8 ++++---- 23 files changed, 58 insertions(+), 39 deletions(-) diff --git a/stats/pwc-current.json b/stats/pwc-current.json index ed347fae90..03ba19f459 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -276,6 +276,20 @@ "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green", + "name" : "Simon Green" + }, { "data" : [ [ @@ -470,6 +484,11 @@ "name" : "Roger Bell_West", "y" : 3 }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 3 + }, { "drilldown" : "Thomas Kohler", "name" : "Thomas Kohler", @@ -500,7 +519,7 @@ } ], "subtitle" : { - "text" : "[Champions: 27] Last updated at 2025-11-02 11:05:04 GMT" + "text" : "[Champions: 28] Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge - 345" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index cc239a2bf2..0753ae484a 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index b0fb6bd2aa..28fdee3bcc 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 3d8a721b2d..291404c565 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 2f598639d2..3930438006 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 5574c3979a..8ac85904da 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 776e49d23b..0e19ce6995 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-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 1a93b16da4..ab6d4f5129 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,7 +8,7 @@ "data" : [ [ "Perl", - 41 + 43 ], [ "Raku", @@ -16,7 +16,7 @@ ], [ "Blog", - 14 + 15 ] ], "id" : "345", @@ -799,7 +799,7 @@ { "drilldown" : "345", "name" : "345", - "y" : 74 + "y" : 77 }, { "drilldown" : "344", @@ -1016,7 +1016,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index f2d2079f95..bc9db5b431 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,7 +10,7 @@ "data" : [ [ "Perl", - 17789 + 17791 ], [ "Raku", @@ -18,7 +18,7 @@ ], [ "Blog", - 6375 + 6376 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-11-02 11:05:04 GMT" + "text" : "Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index e93c00f204..c462a43684 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -262,11 +262,11 @@ "data" : [ [ "Perl", - 437 + 439 ], [ "Blog", - 216 + 217 ] ], "id" : "Simon Green", @@ -872,7 +872,7 @@ { "drilldown" : "Simon Green", "name" : "16: Simon Green", - "y" : 1306 + "y" : 1312 }, { "drilldown" : "Peter Campbell Smith", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 9a996e700d..e4fe73ee20 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 08120cc2ae..0803a3af47 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 ab2854235e..9ca3598ca1 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 f12304ea4f..751a9f1c3b 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 756d683ad7..1e34446c61 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 c189e9b7ca..c44730986f 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 9596ff49cf..d2990c7289 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -19,7 +19,7 @@ 0, 22, 0, - 437, + 439, 7, 5, 4, @@ -89,7 +89,7 @@ 0, 0, 3, - 216, + 217, 0, 17, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 5bfd9d672d..fe24eac9d0 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-11-02 11:05:04 GMT" + "text" : "[Champions: 28] Last updated at 2025-11-02 13:11:34 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 aa568d88bd..c9044c01e3 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -69,8 +69,8 @@ 9, 0, 0, - 17, 2, + 17, 0, 194, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 e5e89c1c76..b3be810999 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 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 5a7194cdd8..56a3269dd6 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-11-02 11:05:04 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index 41b8efe26d..032b04df2d 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -289,7 +289,7 @@ 0, 11, 0, - 224, + 225, 5, 3, 2, @@ -955,7 +955,7 @@ 0, 0, 2, - 216, + 217, 0, 15, 0, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-11-02 11:05:04 GMT" + "text" : "[Champions: 328] Last updated at 2025-11-02 13:11:34 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 2e8d2c475b..199c2679b4 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,7 +8,7 @@ "data" : [ [ "Perl", - 2012 + 2014 ], [ "Raku", @@ -16,7 +16,7 @@ ], [ "Blog", - 785 + 786 ] ], "id" : "2025", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 3784 + "y" : 3787 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 11:05:04 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit From aa728e77bec9b3cedf43273a8904c9b1bd38d1fa Mon Sep 17 00:00:00 2001 From: PerlMonk-Athanasius Date: Sun, 2 Nov 2025 23:34:52 +1000 Subject: Perl & Raku solutions to Tasks 1 & 2 for Week 345 --- challenge-345/athanasius/perl/ch-1.pl | 193 +++++++++++++++++++++++++++++ challenge-345/athanasius/perl/ch-2.pl | 213 ++++++++++++++++++++++++++++++++ challenge-345/athanasius/raku/ch-1.raku | 183 +++++++++++++++++++++++++++ challenge-345/athanasius/raku/ch-2.raku | 207 +++++++++++++++++++++++++++++++ 4 files changed, 796 insertions(+) create mode 100644 challenge-345/athanasius/perl/ch-1.pl create mode 100644 challenge-345/athanasius/perl/ch-2.pl create mode 100644 challenge-345/athanasius/raku/ch-1.raku create mode 100644 challenge-345/athanasius/raku/ch-2.raku diff --git a/challenge-345/athanasius/perl/ch-1.pl b/challenge-345/athanasius/perl/ch-1.pl new file mode 100644 index 0000000000..50c8526059 --- /dev/null +++ b/challenge-345/athanasius/perl/ch-1.pl @@ -0,0 +1,193 @@ +#!perl + +################################################################################ +=comment + +Perl Weekly Challenge 345 +========================= + +TASK #1 +------- +*Peak Positions* + +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers, @ints. + +Find all the peaks in the array, a peak is an element that is strictly greater +than its left and right neighbours. Return the indices of all such peak posi- +tions. + +Example 1 + + Input: @ints = (1, 3, 2) + Output: (1) + +Example 2 + + Input: @ints = (2, 4, 6, 5, 3) + Output: (2) + +Example 3 + + Input: @ints = (1, 2, 3, 2, 4, 1) + Output: (2, 4) + +Example 4 + + Input: @ints = (5, 3, 1) + Output: (0) + +Example 5 + + Input: @ints = (1, 5, 1, 5, 1, 5, 1) + Output: (1, 3, 5) + +=cut +################################################################################ + +#--------------------------------------# +# Copyright © 2025 PerlMonk Athanasius # +#--------------------------------------# + +#=============================================================================== +=comment + +Assumption +---------- +From Example 4, it appears that an integer in either end position is considered +to be "strictly greater than" its non-existent neighbour. + +Interface +--------- +1. If no command-line arguments are given, the test suite is run. Otherwise: +2. A non-empty list of integers is entered on the command-line. + +=cut +#=============================================================================== + +use v5.38.2; # Enables strictures +use warnings; +use Const::Fast; +use Regexp::Common qw( number ); +use Test::More; + +const my $USAGE => < ...] + perl $0 + + [ ...] A non-empty list of integers +END +#------------------------------------------------------------------------------- +BEGIN +#------------------------------------------------------------------------------- +{ + $| = 1; + print "\nChallenge 345, Task #1: Peak Positions (Perl)\n\n"; +} + +#=============================================================================== +MAIN: +#=============================================================================== +{ + if (scalar @ARGV == 0) + { + run_tests(); + } + else + { + my @ints = @ARGV; + + / ^ $RE{num}{int} $ /x or error( qq["$_" is not a valid integer] ) + for @ints; + + printf "Input: \@ints = (%s)\n", join ', ', @ints; + + my $peaks = find_peaks( \@ints ); + + printf "Output: (%s)\n", join ', ', @$peaks; + } +} + +#------------------------------------------------------------------------------- +sub find_peaks +#------------------------------------------------------------------------------- +{ + my ($ints) = @_; + my $size = scalar @$ints; + my @peaks; + + if ($size == 0) + { + die 'Empty integer list'; + } + elsif ($size == 1) + { + push @peaks, 0; + } + else + { + my $e = $#$ints; + + push @peaks, 0 if $ints->[0] > $ints->[1]; + + for my $i (1 .. $e - 1) + { + push @peaks, $i if $ints->[$i] > $ints->[$i - 1] && + $ints->[$i] > $ints->[$i + 1] + } + + push @peaks, $e if $ints->[$e] > $ints->[$e - 1]; + } + + return \@peaks; +} + +#------------------------------------------------------------------------------- +sub run_tests +#------------------------------------------------------------------------------- +{ + print "Running the test suite\n"; + + while (my $line = ) + { + chomp $line; + + my ($test_name, $ints_str, $expd_str) = split / \| /x, $line; + + for ($test_name, $ints_str, $expd_str) + { + s/ ^ \s+ //x; + s/ \s+ $ //x; + } + + my @ints = split / \s+ /x, $ints_str; + my $peaks = find_peaks( \@ints ); + my @expd = split / \s+ /x, $expd_str; + + is_deeply $peaks, \@expd, $test_name; + } + + done_testing; +} + +#------------------------------------------------------------------------------- +sub error +#------------------------------------------------------------------------------- +{ + my ($message) = @_; + + die "ERROR: $message\n$USAGE"; +} + +################################################################################ + +__DATA__ +Example 1|1 3 2 |1 +Example 2|2 4 6 5 3 |2 +Example 3|1 2 3 2 4 1 |2 4 +Example 4|5 3 1 |0 +Example 5|1 5 1 5 1 5 1|1 3 5 +Singleton|4 |0 +Negatives|0 -1 1 -2 0 |0 2 4 diff --git a/challenge-345/athanasius/perl/ch-2.pl b/challenge-345/athanasius/perl/ch-2.pl new file mode 100644 index 0000000000..03f48be9ab --- /dev/null +++ b/challenge-345/athanasius/perl/ch-2.pl @@ -0,0 +1,213 @@ +#!perl + +################################################################################ +=comment + +Perl Weekly Challenge 345 +========================= + +TASK #2 +------- +*Last Visitor* + +Submitted by: Mohammad Sajid Anwar + +You are given an integer array @ints where each element is either a positive +integer or -1. + +We process the array from left to right while maintaining two lists: + + @seen: stores previously seen positive integers (newest at the front) + @ans: stores the answers for each -1 + +Rules: + + If $ints[i] is a positive number -> insert it at the front of @seen + If $ints[i] is -1: + +Let $x be how many -1s in a row we've seen before this one. + +If $x < len(@seen) -> append seen[x] to @ans + +Else -> append -1 to @ans + +At the end, return @ans. + +Example 1 + + Input: @ints = (5, -1, -1) + Output: (5, -1) + + @seen = (5) + First -1: @ans = (5) + Second -1: @ans = (5, -1) + +Example 2 + + Input: @ints = (3, 7, -1, -1, -1) + Output: (7, 3, -1) + + @seen = (3, 7) + First -1: @ans = (7) + Second -1: @ans = (7, 3) + Third -1: @ans = (7, 3, -1) + +Example 3 + + Input: @ints = (2, -1, 4, -1, -1) + Output: (2, 4, 2) + +Example 4 + + Input: @ints = (10, 20, -1, 30, -1, -1) + Output: (20, 30, 20) + +Example 5 + + Input: @ints = (-1, -1, 5, -1) + Output: (-1, -1, 5) + +=cut +################################################################################ + +#--------------------------------------# +# Copyright © 2025 PerlMonk Athanasius # +#--------------------------------------# + +#=============================================================================== +=comment + +Assumptions +----------- +1. A "positive integer" is any non-negative integer (i.e., including zero). + Hence, the allowed values in @ints are integers in the range: -1, 0, 1, ... +2. "Let $x be how many -1s in a row we've seen before this one." should read: + "Let $x be how many -1s in a row we've seen *immediately* before this one." + +Interface +--------- +1. If no command-line arguments are given, the test suite is run. Otherwise: +2. A non-empty list of integers is entered on the command-line; each integer is + greater than or equal to -1. + +=cut +#=============================================================================== + +use v5.38.2; # Enables strictures +use warnings; +use Const::Fast; +use Regexp::Common qw( number ); +use Test::More; + +const my $USAGE => < ...] + perl $0 + + [ ...] A non-empty list of integers, each -1 or greater +END + +#------------------------------------------------------------------------------- +BEGIN +#------------------------------------------------------------------------------- +{ + $| = 1; + print "\nChallenge 345, Task #2: Last Visitor (Perl)\n\n"; +} + +#=============================================================================== +MAIN: +#=============================================================================== +{ + if (scalar @ARGV == 0) + { + run_tests(); + } + else + { + my @ints = @ARGV; + + for (@ints) + { + / ^ $RE{num}{int} $ /x or error( qq["$_" is not a valid integer] ); + $_ >= -1 or error( qq["$_" is too small]); + } + + printf "Input: \@ints = (%s)\n", join ', ', @ints; + + my $ans = find_answers( \@ints ); + + printf "Output: (%s)\n", join ', ', @$ans; + } +} + +#------------------------------------------------------------------------------- +sub find_answers +#------------------------------------------------------------------------------- +{ + my ($ints) = @_; + my (@seen, @ans); + my $x = 0; + + for my $n (@$ints) + { + if ($n >= 0) + { + unshift @seen, $n; + $x = 0; + } + else + { + push @ans, (scalar @seen > $x) ? $seen[$x] : -1; + ++$x; + } + } + + return \@ans; +} + +#------------------------------------------------------------------------------- +sub run_tests +#------------------------------------------------------------------------------- +{ + print "Running the test suite\n"; + + while (my $line = ) + { + chomp $line; + + my ($test_name, $ints_str, $expd_str) = split / \| /x, $line; + + for ($test_name, $ints_str, $expd_str) + { + s/ ^ \s+ //x; + s/ \s+ $ //x; + } + + my @ints = split / \s+ /x, $ints_str; + my $ans = find_answers( \@ints ); + my @expd = split / \s+ /x, $expd_str; + + is_deeply $ans, \@expd, $test_name; + } + + done_testing; +} + +#------------------------------------------------------------------------------- +sub error +#------------------------------------------------------------------------------- +{ + my ($message) = @_; + + die "ERROR: $message\n$USAGE"; +} + +################################################################################ + +__DATA__ +Example 1| 5 -1 -1 | 5 -1 +Example 2| 3 7 -1 -1 -1 | 7 3 -1 +Example 3| 2 -1 4 -1 -1 | 2 4 2 +Example 4|10 20 -1 30 -1 -1|20 30 20 +Example 5|-1 -1 5 -1 |-1 -1 5 diff --git a/challenge-345/athanasius/raku/ch-1.raku b/challenge-345/athanasius/raku/ch-1.raku new file mode 100644 index 0000000000..9668f9c78a --- /dev/null +++ b/challenge-345/athanasius/raku/ch-1.raku @@ -0,0 +1,183 @@ +use v6d; + +################################################################################ +=begin comment + +Perl Weekly Challenge 345 +========================= + +TASK #1 +------- +*Peak Positions* + +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers, @ints. + +Find all the peaks in the array, a peak is an element that is strictly greater +than its left and right neighbours. Return the indices of all such peak posi- +tions. + +Example 1 + + Input: @ints = (1, 3, 2) + Output: (1) + +Example 2 + + Input: @ints = (2, 4, 6, 5, 3) + Output: (2) + +Example 3 + + Input: @ints = (1, 2, 3, 2, 4, 1) + Output: (2, 4) + +Example 4 + + Input: @ints = (5, 3, 1) + Output: (0) + +Example 5 + + Input: @ints = (1, 5, 1, 5, 1, 5, 1) + Output: (1, 3, 5) + +=end comment +################################################################################ + +#--------------------------------------# +# Copyright © 2025 PerlMonk Athanasius # +#--------------------------------------# + +#=============================================================================== +=begin comment + +Assumption +---------- +From Example 4, it appears that an integer in either end position is considered +to be "strictly greater than" its non-existent neighbour. + +Interface +--------- +1. If no command-line arguments are given, the test suite is run. Otherwise: +2. A non-empty list of integers is entered on the command-line. +3. If the first integer is negative, it must be preceded by "--" to signal that + it is not a command-line flag. + +=end comment +#=============================================================================== + +use Test; + +#------------------------------------------------------------------------------- +BEGIN +#------------------------------------------------------------------------------- +{ + "\nChallenge 345, Task #1: Peak Positions (Raku)\n".put; +} + +#=============================================================================== +multi sub MAIN +( + #| A non-empty list of integers + + *@ints where { .elems > 0 && .all ~~ Int:D } +) +#=============================================================================== +{ + "Input: \@ints = (%s)\n".printf: @ints.join: ', '; + + my UInt @peaks = find-peaks( @ints ); + + "Output: (%s)\n".printf: @peaks.join: ', '; +} + +#=============================================================================== +multi sub MAIN() # No input: run the test suite +#=============================================================================== +{ + run-tests(); +} + +#------------------------------------------------------------------------------- +sub find-peaks( List:D[Int:D] $ints where { .elems > 0 } --> List:D[UInt:D] ) +#------------------------------------------------------------------------------- +{ + my UInt @peaks; + + if $ints.elems == 1 + { + @peaks.push: 0; + } + else + { + my UInt $e = $ints.end; + + @peaks.push: 0 if $ints[0] > $ints[1]; + + for 1 .. $e - 1 -> UInt $i + { + @peaks.push: $i if $ints[$i] > $ints[$i - 1] && + $ints[$i] > $ints[$i + 1] + } + + @peaks.push: $e if $ints[$e] > $ints[$e - 1]; + } + + return @peaks; +} + +#------------------------------------------------------------------------------- +sub run-tests() +#------------------------------------------------------------------------------- +{ + 'Running the test suite'.put; + + for test-data.lines -> Str $line + { + my Str ($test-name, $ints-str, $expd-str) = $line.split: / \| /; + + for $test-name, $ints-str, $expd-str + { + s/ ^ \s+ //; + s/ \s+ $ //; + } + + my Int @ints = $ints-str.split( / \s+ /, :skip-empty ).map: { .Int }; + my UInt @peaks = find-peaks( @ints ); + my UInt @expd = $expd-str.split( / \s+ /, :skip-empty ).map: { .Int }; + + is-deeply @peaks, @expd, $test-name; + } + + done-testing; +} + +#------------------------------------------------------------------------------- +sub USAGE() +#------------------------------------------------------------------------------- +{ + my Str $usage = $*USAGE; + + $usage ~~ s:g/ ($*PROGRAM-NAME) /raku $0/; + + $usage.put; +} + +#------------------------------------------------------------------------------- +sub test-data( --> Str:D ) +#------------------------------------------------------------------------------- +{ + return q:to/END/; + Example 1|1 3 2 |1 + Example 2|2 4 6 5 3 |2 + Example 3|1 2 3 2 4 1 |2 4 + Example 4|5 3 1 |0 + Example 5|1 5 1 5 1 5 1|1 3 5 + Singleton|4 |0 + Negatives|0 -1 1 -2 0 |0 2 4 + END +} + +################################################################################ diff --git a/challenge-345/athanasius/raku/ch-2.raku b/challenge-345/athanasius/raku/ch-2.raku new file mode 100644 index 0000000000..e1ad9a7797 --- /dev/null +++ b/challenge-345/athanasius/raku/ch-2.raku @@ -0,0 +1,207 @@ +use v6d; + +################################################################################ +=begin comment + +Perl Weekly Challenge 345 +========================= + +TASK #2 +------- +*Last Visitor* + +Submitted by: Mohammad Sajid Anwar + +You are given an integer array @ints where each element is either a positive +integer or -1. + +We process the array from left to right while maintaining two lists: + + @seen: stores previously seen positive integers (newest at the front) + @ans: stores the answers for each -1 + +Rules: + + If $ints[i] is a positive number -> insert it at the front of @seen + If $ints[i] is -1: + +Let $x be how many -1s in a row we've seen before this one. + +If $x < len(@seen) -> append seen[x] to @ans + +Else -> append -1 to @ans + +At the end, return @ans. + +Example 1 + + Input: @ints = (5, -1, -1) + Output: (5, -1) + + @seen = (5) + First -1: @ans = (5) + Second -1: @ans = (5, -1) + +Example 2 + + Input: @ints = (3, 7, -1, -1, -1) + Output: (7, 3, -1) + + @seen = (3, 7) + First -1: @ans = (7) + Second -1: @ans = (7, 3) + Third -1: @ans = (7, 3, -1) + +Example 3 + + Input: @ints = (2, -1, 4, -1, -1) + Output: (2, 4, 2) + +Example 4 + + Input: @ints = (10, 20, -1, 30, -1, -1) + Output: (20, 30, 20) + +Example 5 + + Input: @ints = (-1, -1, 5, -1) + Output: (-1, -1, 5) + +=end comment +################################################################################ + +#--------------------------------------# +# Copyright © 2025 PerlMonk Athanasius # +#--------------------------------------# + +#=============================================================================== +=begin comment + +Assumptions +----------- +1. A "positive integer" is any non-negative integer (i.e., including zero). + Hence, the allowed values in @ints are integers in the range: -1, 0, 1, ... +2. "Let $x be how many -1s in a row we've seen before this one." should read: + "Let $x be how many -1s in a row we've seen *immediately* before this one." + +Interface +--------- +1. If no command-line arguments are given, the test suite is run. Otherwise: +2. A non-empty list of integers is entered on the command-line; each integer is + greater than or equal to -1. +3. If the first such integer is -1, it must be preceded by "--" to signal that + it is not a command-line flag. + +=end comment +#=============================================================================== + +use Test; + +subset Type of Int where * >= -1; + +#------------------------------------------------------------------------------- +BEGIN +#------------------------------------------------------------------------------- +{ + "\nChallenge 345, Task #2: Last Visitor (Raku)\n".put; +} + +#=============================================================================== +multi sub MAIN +( + #| A non-empty list of integers, each -1 or greater + + *@ints where { .elems > 0 && .all ~~ Type:D } +) +#=============================================================================== +{ + "Input: \@ints = (%s)\n".printf: @ints.join: ', '; + + my Type @ans = find-answers( @ints ); + + "Output: (%s)\n".printf: @ans.join: ', '; +} + +#=============================================================================== +multi sub MAIN() # No input: run the test suite +#=============================================================================== +{ + run-tests(); +} + +#------------------------------------------------------------------------------- +sub find-answers( List:D[Type:D] $ints --> List:D[Type:D] ) +#------------------------------------------------------------------------------- +{ + my UInt @seen; + my Type @ans; + my UInt $x = 0; + + for @$ints -> Type $n + { + if $n >= 0 + { + @seen.unshift: $n; + $x = 0; + } + else + { + @ans.push: (@seen.elems > $x) ?? @seen[$x] !! -1; + ++$x; + } + } + + return @ans; +} + +#------------------------------------------------------------------------------- +sub run-tests() +#------------------------------------------------------------------------------- +{ + 'Running the test suite'.put; + + for test-data.lines -> Str $line + { + my Str ($test-name, $ints-str, $expd-str) = $line.split: / \| /; + + for $test-name, $ints-str, $expd-str + { + s/ ^ \s+ //; + s/ \s+ $ //; + } + + my Type @ints = $ints-str.split( / \s+ /, :skip-empty ).map: { .Int }; + my Type @ans = find-answers( @ints ); + my Type @expd = $expd-str.split( / \s+ /, :skip-empty ).map: { .Int }; + + is-deeply @ans, @expd, $test-name; + } + + done-testing; +} + +#------------------------------------------------------------------------------- +sub USAGE() +#------------------------------------------------------------------------------- +{ + my Str $usage = $*USAGE; + + $usage ~~ s:g/ ($*PROGRAM-NAME) /raku $0/; + + $usage.put; +} + +#------------------------------------------------------------------------------- +sub test-data( --> Str:D ) +#------------------------------------------------------------------------------- +{ + return q:to/END/; + Example 1| 5 -1 -1 | 5 -1 + Example 2| 3 7 -1 -1 -1 | 7 3 -1 + Example 3| 2 -1 4 -1 -1 | 2 4 2 + Example 4|10 20 -1 30 -1 -1|20 30 20 + Example 5|-1 -1 5 -1 |-1 -1 5 + END +} + +################################################################################ -- cgit From a5d2acad3d6f5b2e9e874d889f800878db24251d Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Sun, 2 Nov 2025 13:48:43 +0000 Subject: - Added solutions by Athanasius. --- stats/pwc-current.json | 21 ++++++++++++++++++++- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 8 ++++---- stats/pwc-language-breakdown-summary.json | 6 +++--- stats/pwc-leaders.json | 8 ++++---- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 2 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 2 +- stats/pwc-summary-301-330.json | 2 +- stats/pwc-summary-31-60.json | 8 ++++---- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 6 +++--- stats/pwc-yearly-language-summary.json | 8 ++++---- 23 files changed, 58 insertions(+), 39 deletions(-) diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 03ba19f459..a14f95c2c6 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -52,6 +52,20 @@ "id" : "Arne Sommer", "name" : "Arne Sommer" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Athanasius", + "name" : "Athanasius" + }, { "data" : [ [ @@ -394,6 +408,11 @@ "name" : "Arne Sommer", "y" : 3 }, + { + "drilldown" : "Athanasius", + "name" : "Athanasius", + "y" : 4 + }, { "drilldown" : "Bob Lied", "name" : "Bob Lied", @@ -519,7 +538,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-11-02 13:11:34 GMT" + "text" : "[Champions: 29] Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge - 345" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 0753ae484a..1dc9bb5a95 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index 28fdee3bcc..3a5e3cfcd7 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 291404c565..91a1b7cfe5 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 3930438006..2a8134f5b6 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 8ac85904da..18d1bc1f2d 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 0e19ce6995..62e6bed369 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-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index ab6d4f5129..a2ce34b584 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 43 + 45 ], [ "Raku", - 19 + 21 ], [ "Blog", @@ -799,7 +799,7 @@ { "drilldown" : "345", "name" : "345", - "y" : 77 + "y" : 81 }, { "drilldown" : "344", @@ -1016,7 +1016,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index bc9db5b431..889144f70e 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,11 +10,11 @@ "data" : [ [ "Perl", - 17791 + 17793 ], [ "Raku", - 9863 + 9865 ], [ "Blog", @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-11-02 13:11:34 GMT" + "text" : "Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index c462a43684..d01c422669 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -94,11 +94,11 @@ "data" : [ [ "Perl", - 582 + 584 ], [ "Raku", - 543 + 545 ], [ "Blog", @@ -822,7 +822,7 @@ { "drilldown" : "Athanasius", "name" : "6: Athanasius", - "y" : 2258 + "y" : 2266 }, { "drilldown" : "Ulrich Rieke", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index e4fe73ee20..d48da79d0c 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 0803a3af47..61f28aafb1 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 9ca3598ca1..23c0528e3a 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 751a9f1c3b..c96af7aec0 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 1e34446c61..f312c9680c 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 c44730986f..e7a176dffd 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 d2990c7289..78aeac20b0 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 fe24eac9d0..b43430f6f0 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-11-02 13:11:34 GMT" + "text" : "[Champions: 28] Last updated at 2025-11-02 13:48:38 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 c9044c01e3..4a323b5732 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -10,7 +10,7 @@ "series" : [ { "data" : [ - 582, + 584, 0, 6, 45, @@ -45,7 +45,7 @@ }, { "data" : [ - 543, + 545, 0, 0, 0, @@ -69,8 +69,8 @@ 9, 0, 0, - 2, 17, + 2, 0, 194, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 b3be810999..f28672e46e 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 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 56a3269dd6..4cc696b0ff 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-11-02 13:11:34 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index 032b04df2d..91ab26398c 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -40,7 +40,7 @@ 83, 6, 0, - 311, + 312, 0, 4, 31, @@ -373,7 +373,7 @@ 344, 0, 14, - 294, + 295, 0, 0, 0, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-11-02 13:11:34 GMT" + "text" : "[Champions: 328] Last updated at 2025-11-02 13:48:38 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 199c2679b4..1baef92cfc 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 2014 + 2016 ], [ "Raku", - 987 + 989 ], [ "Blog", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 3787 + "y" : 3791 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:11:34 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-02 13:48:38 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit From 5834bc8959583d6d7f3c31001916abffef9afecb Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 2 Nov 2025 17:17:41 +0000 Subject: add solution week345 task 1 in python --- challenge-345/steven-wilson/python/ch_1.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-345/steven-wilson/python/ch_1.py diff --git a/challenge-345/steven-wilson/python/ch_1.py b/challenge-345/steven-wilson/python/ch_1.py new file mode 100644 index 0000000000..a07ed939a9 --- /dev/null +++ b/challenge-345/steven-wilson/python/ch_1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + + +def peak_position(ints): + """ Given an array of integers, find all the peaks in the array, a peak is + an element that is strictly greater than its left and right neighbours. + Return the indices of all such peak positions. + >>> peak_position([1, 3, 2]) + [1] + >>> peak_position([2, 4, 6, 5, 3]) + [2] + >>> peak_position([1, 2, 3, 2, 4, 1]) + [2, 4] + >>> peak_position([5, 3, 1]) + [] + >>> peak_position([1, 5, 1, 5, 1, 5, 1]) + [1, 3, 5] + """ + return [n for n, i in enumerate(ints) if n > 0 and n < len(ints) - 1 + and i > ints[n-1] and i > ints[n + 1]] + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) -- cgit From c40559f4dd8f83561233f93faadde955d70343b7 Mon Sep 17 00:00:00 2001 From: orthoplex <> Date: Sun, 2 Nov 2025 21:34:28 +0100 Subject: Week 345 in Uiua --- challenge-345/orthoplex/uiua/ch-1.ua | 9 +++++++++ challenge-345/orthoplex/uiua/ch-2.ua | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 challenge-345/orthoplex/uiua/ch-1.ua create mode 100644 challenge-345/orthoplex/uiua/ch-2.ua diff --git a/challenge-345/orthoplex/uiua/ch-1.ua b/challenge-345/orthoplex/uiua/ch-1.ua new file mode 100644 index 0000000000..4b9407592a --- /dev/null +++ b/challenge-345/orthoplex/uiua/ch-1.ua @@ -0,0 +1,9 @@ +PeakPositions ← ⊚↘₁↧⬚¯∞⧈⊃>⋅< + +┌─╴test + ⍤⤙≍[1] PeakPositions [1 3 2] + ⍤⤙≍[2] PeakPositions [2 4 6 5 3] + ⍤⤙≍[2 4] PeakPositions [1 2 3 2 4 1] + ⍤⤙≍[0] PeakPositions [5 3 1] + ⍤⤙≍[1 3 5] PeakPositions [1 5 1 5 1 5 1] +└─╴ diff --git a/challenge-345/orthoplex/uiua/ch-2.ua b/challenge-345/orthoplex/uiua/ch-2.ua new file mode 100644 index 0000000000..dba975537b --- /dev/null +++ b/challenge-345/orthoplex/uiua/ch-2.ua @@ -0,0 +1,9 @@ +LastVisitor ← ⬚¯1⊏▽⊃±-⊓\(×+₁)\+⊸¬⟜▽⊸>₀ + +┌─╴test + ⍤⤙≍[5 ¯1] LastVisitor [5 ¯1 ¯1] + ⍤⤙≍[7 3 ¯1] LastVisitor [3 7 ¯1 ¯1 ¯1] + ⍤⤙≍[2 4 2] LastVisitor [2 ¯1 4 ¯1 ¯1] + ⍤⤙≍[20 30 20] LastVisitor [10 20 ¯1 30 ¯1 ¯1] + ⍤⤙≍[¯1 ¯1 5] LastVisitor [¯1 ¯1 5 ¯1] +└─╴ -- cgit From 3e35