diff options
25 files changed, 3013 insertions, 2689 deletions
diff --git a/challenge-286/wanderdoc/perl/ch-1.pl b/challenge-286/wanderdoc/perl/ch-1.pl new file mode 100755 index 0000000000..1c7f6f4de4 --- /dev/null +++ b/challenge-286/wanderdoc/perl/ch-1.pl @@ -0,0 +1,57 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+Write a program which outputs one word of its own script / source code at random. A word is anything between whitespace, including symbols.
+Example 1
+
+If the source code contains a line such as: 'open my $fh, "<", "ch-1.pl" or die;'
+then the program would output each of the words { open, my, $fh,, "<",, "ch-1.pl", or, die; }
+(along with other words in the source) with some positive probability.
+
+Example 2
+
+Technically 'print(" hello ");' is *not* an example program, because it does not
+assign positive probability to the other two words in the script.
+It will never display print(" or ");
+
+Example 3
+
+An empty script is one trivial solution, and here is another:
+echo "42" > ch-1.pl && perl -p -e '' ch-1.pl
+
+=cut
+
+
+self_print();
+
+
+sub self_print
+{
+ my $file = $0;
+ open my $in, "<", $0 or die "$!";
+
+ my @txt;
+ my $flag = 0;
+
+ for my $line ( <$in> )
+ {
+
+ chomp $line;
+ next if $line =~ /^\s*$/;
+ next if $line =~ /^\s*#(?!\!perl)/;
+ if ( $line =~ /^=/ )
+ {
+ if ($flag == 0) {$flag = 1; next;}
+ else {$flag = 0; next;}
+ }
+
+ $line =~ s/#.*// if ($line !~ /#!perl/ and $line !~ /=~/);
+ push @txt, $line if ($flag == 0);;
+ }
+
+ my $full_txt = join(" ", @txt);
+ my @filtered = split(/\s+/, $full_txt);
+ print $filtered[ int(rand(@filtered)) ], $/; # @filtered to make $#filtered possible.
+}
\ No newline at end of file diff --git a/challenge-286/wanderdoc/perl/ch-2.pl b/challenge-286/wanderdoc/perl/ch-2.pl new file mode 100755 index 0000000000..86c6b4e92e --- /dev/null +++ b/challenge-286/wanderdoc/perl/ch-2.pl @@ -0,0 +1,105 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given an array of integers, @ints, whose length is a power of 2.
+
+Write a script to play the order game (min and max) and return the last element.
+Example 1
+
+Input: @ints = (2, 1, 4, 5, 6, 3, 0, 2)
+Output: 1
+
+Operation 1:
+
+ min(2, 1) = 1
+ max(4, 5) = 5
+ min(6, 3) = 3
+ max(0, 2) = 2
+
+Operation 2:
+
+ min(1, 5) = 1
+ max(3, 2) = 3
+
+Operation 3:
+
+ min(1, 3) = 1
+
+Example 2
+
+Input: @ints = (0, 5, 3, 2)
+Output: 0
+
+Operation 1:
+
+ min(0, 5) = 0
+ max(3, 2) = 3
+
+Operation 2:
+
+ min(0, 3) = 0
+
+Example 3
+
+Input: @ints = (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8)
+Output: 2
+
+Operation 1:
+
+ min(9, 2) = 2
+ max(1, 4) = 4
+ min(5, 6) = 5
+ max(0, 7) = 7
+ min(3, 1) = 1
+ max(3, 5) = 5
+ min(7, 9) = 7
+ max(0, 8) = 8
+
+Operation 2:
+
+ min(2, 4) = 2
+ max(5, 7) = 7
+ min(1, 5) = 1
+ max(7, 8) = 8
+
+Operation 3:
+
+ min(2, 7) = 2
+ max(1, 8) = 8
+
+Operation 4:
+
+ min(2, 8) = 2
+
+=cut
+
+use List::Util qw(min max);
+use Test2::V0;
+
+is(order_game(2, 1, 4, 5, 6, 3, 0, 2), 1, 'Example 1');
+is(order_game(0, 5, 3, 2), 0, 'Example 2');
+is(order_game(9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), 2, 'Example 3');
+is(order_game(9, 5, 3 ), 3, 'Example odd');
+
+done_testing();
+
+
+sub order_game
+{
+ my @arr = @_;
+ while ( scalar @arr > 1 )
+ {
+ my @temp;
+ my $flag = 0;
+ while ( @arr )
+ {
+ my @pair = splice(@arr, 0, 2);
+ if ( $flag == 0 ) { push @temp, min(@pair); $flag = 1;}
+ elsif ( $flag == 1 ) { push @temp, max(@pair); $flag = 0;}
+ }
+ @arr = @temp;
+ }
+ return "@arr";
+}
\ No newline at end of file diff --git a/stats/pwc-challenge-285.json b/stats/pwc-challenge-285.json index da6ab52584..fb715e9c22 100644 --- a/stats/pwc-challenge-285.json +++ b/stats/pwc-challenge-285.json @@ -1,225 +1,41 @@ { "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" - }, - "series" : [ - { - "colorByPoint" : 1, - "data" : [ - { - "y" : 3, - "drilldown" : "Ali Moradi", - "name" : "Ali Moradi" - }, - { - "drilldown" : "Andrew Schneider", - "y" : 2, - "name" : "Andrew Schneider" - }, - { - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer", - "y" : 3 - }, - { - "name" : "Asher Harvey-Smith", - "y" : 1, - "drilldown" : "Asher Harvey-Smith" - }, - { - "name" : "Athanasius", - "drilldown" : "Athanasius", - "y" : 4 - }, - { - "name" : "BarrOff", - "y" : 1, - "drilldown" : "BarrOff" - }, - { - "y" : 2, - "drilldown" : "Bob Lied", - "name" : "Bob Lied" - }, - { - "drilldown" : "Cheok-Yin Fung", - "y" : 2, - "name" : "Cheok-Yin Fung" - }, - { - "name" : "Dave Jacoby", - "y" : 2, - "drilldown" : "Dave Jacoby" - }, - { - "name" : "David Ferrone", - "drilldown" : "David Ferrone", - "y" : 3 - }, - { - "y" : 2, - "drilldown" : "E. Choroba", - "name" : "E. Choroba" - }, - { - "name" : "Feng Chang", - "y" : 2, - "drilldown" : "Feng Chang" - }, - { - "name" : "Jan Krnavek", - "drilldown" : "Jan Krnavek", - "y" : 1 - }, - { - "drilldown" : "Jorg Sommrey", - "y" : 3, - "name" : "Jorg Sommrey" - }, - { - "name" : "Kjetil Skotheim", - "drilldown" : "Kjetil Skotheim", - "y" : 2 - }, - { - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld", - "y" : 6 - }, - { - "drilldown" : "Mark Anderson", - "y" : 2, - "name" : "Mark Anderson" - }, - { - "name" : "Matthew Neleigh", - "y" : 2, - "drilldown" : "Matthew Neleigh" - }, - { - "name" : "Matthias Muth", - "y" : 3, - "drilldown" : "Matthias Muth" - }, - { - "name" : "Nelo Tovar", - "drilldown" : "Nelo Tovar", - "y" : 2 - }, - { - "name" : "Packy Anderson", - "y" : 5, - "drilldown" : "Packy Anderson" - }, - { - "drilldown" : "Paulo Custodio", - "y" : 2, - "name" : "Paulo Custodio" - }, - { - "name" : "Peter Campbell Smith", - "drilldown" : "Peter Campbell Smith", - "y" : 3 - }, - { - "y" : 2, - "drilldown" : "Peter Meszaros", - "name" : "Peter Meszaros" - }, - { - "name" : "Reinier Maliepaard", - "drilldown" : "Reinier Maliepaard", - "y" : 2 - }, - { - "name" : "Robbie Hatley", - "drilldown" : "Robbie Hatley", - "y" : 3 - }, - { - "y" : 2, - "drilldown" : "Robert Ransbottom", - "name" : "Robert Ransbottom" - }, - { - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West", - "y" : 5 - }, - { - "y" : 2, - "drilldown" : "Santiago Leyva", - "name" : "Santiago Leyva" - }, - { - "name" : "Simon Green", - "drilldown" : "Simon Green", - "y" : 3 - }, - { - "y" : 4, - "drilldown" : "Thomas Kohler", - "name" : "Thomas Kohler" - }, - { - "name" : "Tim King", - "drilldown" : "Tim King", - "y" : 2 - }, - { - "name" : "Torgny Lyon", - "drilldown" : "Torgny Lyon", - "y" : 3 - }, - { - "drilldown" : "Ulrich Rieke", - "y" : 4, - "name" : "Ulrich Rieke" - }, - { - "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 - }, - { - "name" : "Wanderdoc", - "drilldown" : "Wanderdoc", - "y" : 2 - } - ], - "name" : "The Weekly Challenge - 285" - } - ], - "subtitle" : { - "text" : "[Champions: 36] Last updated at 2024-09-15 08:25:00 GMT" + "chart" : { + "type" : "column" }, "title" : { "text" : "The Weekly Challenge - 285" }, + "xAxis" : { + "type" : "category" + }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, - "chart" : { - "type" : "column" + "subtitle" : { + "text" : "[Champions: 37] Last updated at 2024-09-15 21:39:43 GMT" }, "legend" : { "enabled" : 0 }, + "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 + }, "drilldown" : { "series" : [ { - "id" : "Ali Moradi", "data" : [ [ "Perl", @@ -230,20 +46,21 @@ 1 ] ], - "name" : "Ali Moradi" + "name" : "Ali Moradi", + "id" : "Ali Moradi" }, { - "id" : "Andrew Schneider", "name" : "Andrew Schneider", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Andrew Schneider" }, { - "name" : "Arne Sommer", + "id" : "Arne Sommer", "data" : [ [ "Raku", @@ -254,17 +71,17 @@ 1 ] ], - "id" : "Arne Sommer" + "name" : "Arne Sommer" }, { - "id" : "Asher Harvey-Smith", - "name" : "Asher Harvey-Smith", "data" : [ [ "Raku", 1 ] - ] + ], + "name" : "Asher Harvey-Smith", + "id" : "Asher Harvey-Smith" }, { "id" : "Athanasius", @@ -301,26 +118,28 @@ "name" : "Bob Lied" }, { + "id" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] ], - "name" : "Cheok-Yin Fung", - "id" : "Cheok-Yin Fung" + "name" : "Cheok-Yin Fung" }, { - "id" : "Dave Jacoby", "data" : [ [ "Perl", 2 ] ], - "name" : "Dave Jacoby" + "name" : "Dave Jacoby", + "id" : "Dave Jacoby" }, { + "id" : "David Ferrone", + "name" : "David Ferrone", "data" : [ [ "Perl", @@ -330,9 +149,7 @@ "Blog", 1 ] - ], - "name" : "David Ferrone", - "id" : "David Ferrone" + ] }, { "name" : "E. Choroba", @@ -345,14 +162,32 @@ "id" : "E. Choroba" }, { + "id" : "Feng Chang", "name" : "Feng Chang", "data" : [ [ "Raku", 2 ] + ] + }, + { + "id" : "Jaldhar H. Vyas", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] ], - "id" : "Feng Chang" + "name" : "Jaldhar H. Vyas" }, { "id" : "Jan Krnavek", @@ -365,6 +200,7 @@ ] }, { + "id" : "Jorg Sommrey", "data" : [ [ "Perl", @@ -375,18 +211,17 @@ 1 ] ], - "name" : "Jorg Sommrey", - "id" : "Jorg Sommrey" + "name" : "Jorg Sommrey" }, { "id" : "Kjetil Skotheim", - "name" : "Kjetil Skotheim", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Kjetil Skotheim" }, { "id" : "Laurent Rosenfeld", @@ -407,27 +242,26 @@ "name" : "Laurent Rosenfeld" }, { - "id" : "Mark Anderson", "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Mark Anderson" }, { - "id" : "Matthew Neleigh", - "name" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Matthew Neleigh", + "id" : "Matthew Neleigh" }, { - "id" : "Matthias Muth", "data" : [ [ "Perl", @@ -438,7 +272,8 @@ 1 ] ], - "name" : "Matthias Muth" + "name" : "Matthias Muth", + "id" : "Matthias Muth" }, { "name" : "Nelo Tovar", @@ -469,17 +304,16 @@ "id" : "Packy Anderson" }, { - "name" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] ], + "name" : "Paulo Custodio", "id" : "Paulo Custodio" }, { - "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -490,7 +324,8 @@ 1 ] ], - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { "id" : "Peter Meszaros", @@ -503,7 +338,6 @@ ] }, { - "id" : "Reinier Maliepaard", "data" : [ [ "Perl", @@ -514,7 +348,8 @@ 1 ] ], - "name" : "Reinier Maliepaard" + "name" : "Reinier Maliepaard", + "id" : "Reinier Maliepaard" }, { "id" : "Robbie Hatley", @@ -531,14 +366,14 @@ ] }, { + "id" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] ], - "name" : "Robert Ransbottom", - "id" : "Robert Ransbottom" + "name" : "Robert Ransbottom" }, { "id" : "Roger Bell_West", @@ -583,7 +418,6 @@ "name" : "Simon Green" }, { - "id" : "Thomas Kohler", "name" : "Thomas Kohler", "data" : [ [ @@ -594,19 +428,21 @@ "Blog", 2 ] - ] + ], + "id" : "Thomas Kohler" }, { + "id" : "Tim King", + "name" : "Tim King", "data" : [ [ "Perl", 2 ] - ], - "name" : "Tim King", - "id" : "Tim King" + ] }, { + "name" : "Torgny Lyon", "data" : [ [ "Perl", @@ -617,11 +453,11 @@ 1 ] ], - "name" : "Torgny Lyon", "id" : "Torgny Lyon" }, { "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -631,10 +467,10 @@ "Raku", 2 ] - ], - "name" : "Ulrich Rieke" + ] }, { + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -645,8 +481,7 @@ 1 ] ], - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan" + "name" : "W. Luis Mochan" }, { "id" : "Wanderdoc", @@ -660,9 +495,197 @@ } ] }, - "tooltip" : { - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" - } + "series" : [ + { + "data" : [ + { + "name" : "Ali Moradi", + "y" : 3, + "drilldown" : "Ali Moradi" + }, + { + "name" : "Andrew Schneider", + "y" : 2, + "drilldown" : "Andrew Schneider" + }, + { + "drilldown" : "Arne Sommer", + "y" : 3, + "name" : "Arne Sommer" + }, + { + "drilldown" : "Asher Harvey-Smith", + "name" : "Asher Harvey-Smith", + "y" : 1 + }, + { + "y" : 4, + "name" : "Athanasius", + "drilldown" : "Athanasius" + }, + { + "y" : 1, + "name" : "BarrOff", + "drilldown" : "BarrOff" + }, + { + "name" : "Bob Lied", + "y" : 2, + "drilldown" : "Bob Lied" + }, + { + "name" : "Cheok-Yin Fung", + "y" : 2, + "drilldown" : "Cheok-Yin Fung" + }, + { + "name" : "Dave Jacoby", + "y" : 2, + "drilldown" : "Dave Jacoby" + }, + { + "name" : "David Ferrone", + "y" : 3, + "drilldown" : "David Ferrone" + }, + { + "y" : 2, + "name" : "E. Choroba", + "drilldown" : "E. Choroba" + }, + { + "drilldown" : "Feng Chang", + "name" : "Feng Chang", + "y" : 2 + }, + { + "drilldown" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas", + "y" : 5 + }, + { + "drilldown" : "Jan Krnavek", + "y" : 1, + "name" : "Jan Krnavek" + }, + { + "name" : "Jorg Sommrey", + "y" : 3, + "drilldown" : "Jorg Sommrey" + }, + { + "name" : "Kjetil Skotheim", + "y" : 2, + "drilldown" : "Kjetil Skotheim" + }, + { + "y" : 6, + "name" : "Laurent Rosenfeld", + "drilldown" : "Laurent Rosenfeld" + }, + { + "name" : "Mark Anderson", + "y" : 2, + "drilldown" : "Mark Anderson" + }, + { + "y" : 2, + "name" : "Matthew Neleigh", + "drilldown" : "Matthew Neleigh" + }, + { + "drilldown" : "Matthias Muth", + "name" : "Matthias Muth", + "y" : 3 + }, + { + "y" : 2, + "name" : "Nelo Tovar", + "drilldown" : "Nelo Tovar" + }, + { + "drilldown" : "Packy Anderson", + "y" : 5, + "name" : "Packy Anderson" + }, + { + "drilldown" : "Paulo Custodio", + "name" : "Paulo Custodio", + "y" : 2 + }, + { + "y" : 3, + "name" : "Peter Campbell Smith", + "drilldown" : "Peter Campbell Smith" + }, + { + "drilldown" : "Peter Meszaros", + "name" : "Peter Meszaros", + "y" : 2 + }, + { + "drilldown" : "Reinier Maliepaard", + "name" : "Reinier Maliepaard", + "y" : 2 + }, + { + "drilldown" : "Robbie Hatley", + "y" : 3, + "name" : "Robbie Hatley" + }, + { + "drilldown" : "Robert Ransbottom", + "y" : 2, + "name" : "Robert Ransbottom" + }, + { + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", + "y" : 5 + }, + { + "name" : "Santiago Leyva", + "y" : 2, + "drilldown" : "Santiago Leyva" + }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 3 + }, + { + "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler", + "y" : 4 + }, + { + "drilldown" : "Tim King", + "y" : 2, + "name" : "Tim King" + }, + { + "drilldown" : "Torgny Lyon", + "y" : 3, + "name" : "Torgny Lyon" + }, + { + "name" : "Ulrich Rieke", + "y" : 4, + "drilldown" : "Ulrich Rieke" + }, + { + "name" : "W. Luis Mochan", + "y" : 3, + "drilldown" : "W. Luis Mochan" + }, + { + "name" : "Wanderdoc", + "y" : 2, + "drilldown" : "Wanderdoc" + } + ], + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 285" + } + ] } diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 839c9d4e31..75ab8c6ca8 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,12 +1,9 @@ { - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } + "subtitle" : { + "text" : "[Champions: 35] Last updated at 2024-09-15 21:40:16 GMT" + }, + "chart" : { + "type" : "column" }, "series" : [ { @@ -18,74 +15,104 @@ "name" : "Alexander Karelas" }, { - "name" : "Ali Moradi", + "y" : 5, "drilldown" : "Ali Moradi", - "y" : 5 + "name" : "Ali Moradi" + }, + { + "drilldown" : "Andrew Schneider", + "y" : 2, + "name" : "Andrew Schneider" }, { + "drilldown" : "Arne Sommer", "y" : 3, - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer" + "name" : "Arne Sommer" + }, + { + "name" : "Asher Harvey-Smith", + "drilldown" : "Asher Harvey-Smith", + "y" : 1 }, { + "y" : 4, "drilldown" : "Athanasius", - "name" : "Athanasius", - "y" : 4 + "name" : "Athanasius" }, { "y" : 1, + "drilldown" : "BarrOff", + "name" : "BarrOff" + }, + { + "drilldown" : "Bob Lied", + "y" : 2, + "name" : "Bob Lied" + }, + { "name" : "Cheok-Yin Fung", + "y" : 1, "drilldown" : "Cheok-Yin Fung" }, { - "name" |
