diff options
27 files changed, 3282 insertions, 2875 deletions
diff --git a/challenge-263/eric-cheung/python/ch-1.py b/challenge-263/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..7c330e0eda --- /dev/null +++ b/challenge-263/eric-cheung/python/ch-1.py @@ -0,0 +1,16 @@ +
+## Example 1
+## arrInt = [1, 5, 3, 2, 4, 2]
+## nK = 2
+
+## Example 2
+## arrInt = [1, 2, 4, 3, 5]
+## nK = 6
+
+## Example 3
+arrInt = [5, 3, 2, 4, 2, 1]
+nK = 4
+
+arrOutput = [nIndxLoop for nIndxLoop, elemLoop in enumerate(sorted(arrInt)) if elemLoop == nK]
+
+print (arrOutput)
diff --git a/challenge-263/eric-cheung/python/ch-2.py b/challenge-263/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..b50b2084d7 --- /dev/null +++ b/challenge-263/eric-cheung/python/ch-2.py @@ -0,0 +1,18 @@ +
+## Example 1
+## arrItem_01 = [[1, 1], [2, 1], [3, 2]]
+## arrItem_02 = [[2, 2], [1, 3]]
+
+## Example 2
+## arrItem_01 = [[1, 2], [2, 3], [1, 3], [3, 2]]
+## arrItem_02 = [[3, 1], [1, 3]]
+
+## Example 3
+arrItem_01 = [[1, 1], [2, 2], [3, 3]]
+arrItem_02 = [[2, 3], [2, 4]]
+
+arrCombine = arrItem_01 + arrItem_02
+arrUniq = set([arrLoop[0] for arrLoop in arrCombine])
+arrOutput = [[elemLoop, sum([arrLoop[1] for arrLoop in arrCombine if arrLoop[0] == elemLoop])] for elemLoop in arrUniq]
+
+print (arrOutput)
diff --git a/challenge-263/james-smith/blog.txt b/challenge-263/james-smith/blog.txt new file mode 100644 index 0000000000..e69ad27da2 --- /dev/null +++ b/challenge-263/james-smith/blog.txt @@ -0,0 +1 @@ +https://challenges.jamessmith.me.uk/weekly/weekly-challenge-263 diff --git a/challenge-263/james-smith/perl/ch-1.pl b/challenge-263/james-smith/perl/ch-1.pl new file mode 100644 index 0000000000..7534c1232c --- /dev/null +++ b/challenge-263/james-smith/perl/ch-1.pl @@ -0,0 +1,5 @@ +sub target_index { + my( $k, @c ) = ( pop, 0, 0, 0 ); + $c[ $_ <=> $k ]++ for @_; + $c[2] .. $c[2] + $c[0] - 1 +} diff --git a/challenge-263/james-smith/perl/ch-2.pl b/challenge-263/james-smith/perl/ch-2.pl new file mode 100644 index 0000000000..784e4ca62c --- /dev/null +++ b/challenge-263/james-smith/perl/ch-2.pl @@ -0,0 +1,7 @@ +sub merge_items { + my %c; + for( @_ ) { + $c{ $_->[0] } += $_->[1] for @{$_} + } + map { [ 0 + $_ => $c{$_} ] } keys %c +} diff --git a/challenge-263/laurent-rosenfeld/blog.txt b/challenge-263/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..90950b58da --- /dev/null +++ b/challenge-263/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2024/04/perl-weekly-challenge-263-target-index.html diff --git a/challenge-263/laurent-rosenfeld/perl/ch-1.pl b/challenge-263/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..674699715d --- /dev/null +++ b/challenge-263/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,18 @@ +use strict; +use warnings; +use feature 'say'; + +sub find_index { + my $target = shift; + my @sorted = sort { $a <=> $b } @_; + my @out = grep {$sorted[$_] == $target} 0..$#sorted; + return "@out" || "()"; +} + +my @tests = ( [2, [1, 5, 3, 2, 4, 2]], + [6, [1, 2, 4, 3, 5]], + [4, [5, 3, 2, 4, 2, 1]] ); +for my $test (@tests) { + printf "%d - %-15s => ", $test->[0], "@{$test->[1]}"; + say find_index @$test[0], @{$test->[1]}; +} diff --git a/challenge-263/laurent-rosenfeld/raku/ch-1.raku b/challenge-263/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..35b95147f4 --- /dev/null +++ b/challenge-263/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,13 @@ +sub find-index ($target, @in) { + my @sorted = @in.sort; + my @out = grep {@sorted[$_] == $target}, 0..@sorted.end; + return @out; +} + +my @tests = (2, (1, 5, 3, 2, 4, 2)), + (6, (1, 2, 4, 3, 5)), + (4, (5, 3, 2, 4, 2, 1)); +for @tests -> @test { + printf "%d - %-15s => ", @test[0], "@test[1]"; + say find-index @test[0], @test[1]; +} diff --git a/challenge-263/wanderdoc/perl/ch-1.pl b/challenge-263/wanderdoc/perl/ch-1.pl new file mode 100755 index 0000000000..97a5973fb5 --- /dev/null +++ b/challenge-263/wanderdoc/perl/ch-1.pl @@ -0,0 +1,53 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given an array of integers, @ints and a target element $k. Write a script to return the list of indices in the sorted array where the element is same as the given target element.
+
+Example 1
+Input: @ints = (1, 5, 3, 2, 4, 2), $k = 2
+Output: (1, 2)
+Sorted array: (1, 2, 2, 3, 4, 5)
+Target indices: (1, 2) as $ints[1] = 2 and $k[2] = 2
+
+Example 2
+Input: @ints = (1, 2, 4, 3, 5), $k = 6
+Output: ()
+No element in the given array matching the given target.
+
+Example 3
+
+Input: @ints = (5, 3, 2, 4, 2, 1), $k = 4
+Output: (4)
+Sorted array: (1, 2, 2, 3, 4, 5)
+Target index: (4) as $ints[4] = 4
+=cut
+
+use Sort::Key qw(nkeysort);
+use List::MoreUtils qw(indexes);
+use integer;
+use Test2::V0;
+
+is(target_index([1, 5, 3, 2, 4, 2], 2), [1, 2], 'Example 1');
+is(target_index([1, 2, 4, 3, 5], 6), [], 'Example 2');
+is(target_index([5, 3, 2, 4, 2, 1], 4), [4], 'Example 3');
+done_testing();
+
+sub target_index
+{
+ my ($aref, $elm) = @_;
+ return
+ [indexes { $_ == $elm } nkeysort {$_} @$aref];
+}
+
+
+
+
+
+
+
+# use Data::Dump;
+# dd target_index([1, 5, 3, 2, 4, 2], 2);
+# dd target_index([1, 2, 4, 3, 5], 6);
+# dd target_index([5, 3, 2, 4, 2, 1], 4);
\ No newline at end of file diff --git a/challenge-263/wanderdoc/perl/ch-2.pl b/challenge-263/wanderdoc/perl/ch-2.pl new file mode 100755 index 0000000000..1f3657bb04 --- /dev/null +++ b/challenge-263/wanderdoc/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given two 2-D array of positive integers, $items1 and $items2 where element is pair of (item_id, item_quantity). Write a script to return the merged items.
+Example 1
+Input: $items1 = [ [1,1], [2,1], [3,2] ] $items2 = [ [2,2], [1,3] ]
+Output: [ [1,4], [2,3], [3,2] ]
+Item id (1) appears 2 times: [1,1] and [1,3]. Merged item now (1,4)
+Item id (2) appears 2 times: [2,1] and [2,2]. Merged item now (2,3)
+Item id (3) appears 1 time: [3,2]
+
+Example 2
+Input: $items1 = [ [1,2], [2,3], [1,3], [3,2] ] $items2 = [ [3,1], [1,3] ]
+Output: [ [1,8], [2,3], [3,3] ]
+
+Example 3
+Input: $items1 = [ [1,1], [2,2], [3,3] ] $items2 = [ [2,3], [2,4] ]
+Output: [ [1,1], [2,9], [3,3] ]
+=cut
+
+use Sort::Key qw(nkeysort);
+use Test2::V0;
+
+
+is(merge_items([ [1,1], [2,1], [3,2] ], [ [2,2], [1,3] ]),
+ [ [1,4], [2,3], [3,2] ], 'Example 1');
+is(merge_items([ [1,2], [2,3], [1,3], [3,2] ], [ [3,1], [1,3] ]),
+ [ [1,8], [2,3], [3,3] ], 'Example 2');
+is(merge_items([ [1,1], [2,2], [3,3] ], [ [2,3], [2,4] ]),
+ [ [1,1], [2,9], [3,3] ], 'Example 3');
+ done_testing();
+
+sub merge_items
+{
+ use integer;
+ my @arefs = @_;
+ my %merge;
+ for my $paar ( map { @$_ } @arefs )
+ {
+ $merge{ $paar->[0] } += $paar->[1];
+ }
+ return [ map { [$_, $merge{$_}] } nkeysort{$_} keys %merge ];
+}
diff --git a/stats/pwc-challenge-262.json b/stats/pwc-challenge-262.json new file mode 100644 index 0000000000..e0c7c6b82c --- /dev/null +++ b/stats/pwc-challenge-262.json @@ -0,0 +1,668 @@ +{ + "legend" : { + "enabled" : 0 + }, + "chart" : { + "type" : "column" + }, + "tooltip" : { + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1 + }, + "xAxis" : { + "type" : "category" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "name" : "Adam Russell", + "y" : 2, + "drilldown" : "Adam Russell" + }, + { + "drilldown" : "Ali Moradi", + "y" : 3, + "name" : "Ali Moradi" + }, + { + "name" : "Andrew Shitov", + "drilldown" : "Andrew Shitov", + "y" : 2 + }, + { + "name" : "Arne Sommer", + "y" : 3, + "drilldown" : "Arne Sommer" + }, + { + "drilldown" : "Asher Harvey-Smith", + "y" : 2, + "name" : "Asher Harvey-Smith" + }, + { + "y" : 4, + "drilldown" : "Athanasius", + "name" : "Athanasius" + }, + { + "y" : 3, + "drilldown" : "BarrOff", + "name" : "BarrOff" + }, + { + "name" : "Bob Lied", + "drilldown" : "Bob Lied", + "y" : 3 + }, + { + "name" : "Bruce Gray", + "drilldown" : "Bruce Gray", + "y" : 2 + }, + { + "name" : "Cheok-Yin Fung", + "y" : 2, + "drilldown" : "Cheok-Yin Fung" + }, + { + "drilldown" : "Dave Jacoby", + "y" : 2, + "name" : "Dave Jacoby" + }, + { + "drilldown" : "David Ferrone", + "y" : 2, + "name" : "David Ferrone" + }, + { + "drilldown" : "E. Choroba", + "y" : 2, + "name" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "y" : 2, + "drilldown" : "Feng Chang" + }, + { + "y" : 2, + "drilldown" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "drilldown" : "Jorg Sommrey", + "y" : 3, + "name" : "Jorg Sommrey" + }, + { + "drilldown" : "Lance Wicks", + "y" : 1, + "name" : "Lance Wicks" + }, + { + "drilldown" : "Laurent Rosenfeld", + "y" : 6, + "name" : "Laurent Rosenfeld" + }, + { + "y" : 2, + "drilldown" : "Lubos Kolouch", + "name" : "Lubos Kolouch" + }, + { + "name" : "Luca Ferrari", + "y" : 11, + "drilldown" : "Luca Ferrari" + }, + { + "y" : 1, + "drilldown" : "Mariano Spadaccini", + "name" : "Mariano Spadaccini" + }, + { + "y" : 2, + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "drilldown" : "Matthew Neleigh", + "y" : 2, + "name" : "Matthew Neleigh" + }, + { + "name" : "Nelo Tovar", + "drilldown" : "Nelo Tovar", + "y" : 2 + }, + { + "drilldown" : "Packy Anderson", + "y" : 5, + "name" : "Packy Anderson" + }, + { + "name" : "Peter Campbell Smith", + "y" : 3, + "drilldown" : "Peter Campbell Smith" + }, + { + "y" : 2, + "drilldown" : "Peter Meszaros", + "name" : "Peter Meszaros" + }, + { + "drilldown" : "Reinier Maliepaard", + "y" : 3, + "name" : "Reinier Maliepaard" + }, + { + "name" : "Robbie Hatley", + "y" : 3, + "drilldown" : "Robbie Hatley" + }, + { + "name" : "Robert Ransbottom", + "drilldown" : "Robert Ransbottom", + "y" : 2 + }, + { + "drilldown" : "Roger Bell_West", + "y" : 5, + "name" : "Roger Bell_West" + }, + { + "drilldown" : "Simon Green", + "y" : 3, + "name" : "Simon Green" + }, + { + "y" : 4, + "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "name" : "Ulrich Rieke", + "y" : 4, + "drilldown" : "Ulrich Rieke" + }, + { + "name" : "W. Luis Mochan", + "y" : 3, + "drilldown" : "W. Luis Mochan" + }, + { + "y" : 2, + "drilldown" : "Wanderdoc", + "name" : "Wanderdoc" + } + ], + "name" : "The Weekly Challenge - 262" + } + ], + "drilldown" : { + "series" : [ + { + "name" : "Adam Russell", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Adam Russell" + }, + { + "name" : "Ali Moradi", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ali Moradi" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" + }, + { + "id" : "Arne Sommer", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer" + }, + { + "id" : "Asher Harvey-Smith", + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Asher Harvey-Smith" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "name" : "Athanasius", + "id" : "Athanasius" + }, + { + "id" : "BarrOff", + "name" : "BarrOff", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Bob Lied", + "id" : "Bob Lied" + }, + { + "id" : "Bruce Gray", + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Bruce Gray" + }, + { + "id" : "Cheok-Yin Fung", + "name" : "Cheok-Yin Fung", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Dave Jacoby", + "name" : "Dave Jacoby", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "David Ferrone", + "name" : "David Ferrone", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "E. Choroba", + "id" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Feng Chang" + }, + { + "id" : "Jan Krnavek", + "name" : "Jan Krnavek", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 1 + ] + ], + "name" : "Lance Wicks", + "id" : "Lance Wicks" + }, + { + "id" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Laurent Rosenfeld" + }, + { + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Luca Ferrari", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 9 + ] + ], + "id" : "Luca Ferrari" + }, + { + "id" : "Mariano Spadaccini", + "data" : [ + [ + "Perl", + 1 + ] + ], + "name" : "Mariano Spadaccini" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Mark Anderson", + "id" : "Mark Anderson" + }, + { + "id" : "Matthew Neleigh", + "name" : "Matthew Neleigh", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Nelo Tovar", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Nelo Tovar" + }, + { + "id" : "Packy Anderson", + "name" : "Packy Anderson", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Peter Meszaros", + "id" : "Peter Meszaros" + }, + { + "id" : "Reinier Maliepaard", + "name" : "Reinier Maliepaard", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "id" : "Robbie Hatley", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Robbie Hatley" + }, + { + "name" : "Robert Ransbottom", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Robert Ransbottom" + }, + { + "id" : "Roger Bell_West", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Roger Bell_West" + }, + { + "name" : "Simon Green", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green" + }, + { + "name" : "Thomas Kohler", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke" + }, + { + "id" : "W. Luis Mochan", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "W. Luis Mochan" + }, + { + "id" : "Wanderdoc", + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Wanderdoc" + } + ] + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "subtitle" : { + "text" : "[Champions: 36] Last updated at 2024-04-01 17:07:54 GMT" + }, + "title" : { + "text" : "The Weekly Challenge - 262" + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 1df091328d..0daf64f3fb 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,156 +1,39 @@ { - "legend" : { - "enabled" : 0 - }, - "subtitle" : { - "text" : "[Champions: 36] Last updated at 2024-04-01 00:05:32 GMT" + "xAxis" : { + "type" : "category" }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, - "title" : { - "text" : "The Weekly Challenge - 262" - }, - "tooltip" : { - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1 - }, "series" : [ { - "colorByPoint" : 1, "data" : [ { - "drilldown" : "Adam Russell", - "name" : "Adam Russell", - "y" : 2 - }, - { - "drilldown" : "Ali Moradi", - "name" : "Ali Moradi", - "y" : 3 - }, - { "y" : 2, "drilldown" : "Andrew Shitov", "name" : "Andrew Shitov" }, { - "y" : 3, - "drilldown" : "Arne Sommer", - "name" : "Arne Sommer" - }, - { - "name" : "Asher Harvey-Smith", - "drilldown" : "Asher Harvey-Smith", - "y" : 2 - }, - { - "name" : "Athanasius", - "drilldown" : "Athanasius", - "y" : 4 - }, - { - "y" : 3, - "drilldown" : "BarrOff", - "name" : "BarrOff" - }, - { - "y" : 3, - "name" : "Bob Lied", - "drilldown" : "Bob Lied" - }, - { - "y" : 2, - "drilldown" : "Bruce Gray", - "name" : "Bruce Gray" - }, - { - "y" : 2, - "drilldown" : "Cheok-Yin Fung", - "name" : "Cheok-Yin Fung" - }, - { - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby", - "y" : 2 - }, - { - "y" : 2, - "name" : "David Ferrone", - "drilldown" : "David Ferrone" - |
