aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-08-21 00:44:40 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-08-21 00:44:40 +0100
commita42c096a9168065b7f35322dda2222c1bf0d3399 (patch)
tree9a2839f462eff4ba529d93fa1b1e7d1e5e07d74e
parent97968dce150c7117b856a288da59b221ee463e46 (diff)
downloadperlweeklychallenge-club-a42c096a9168065b7f35322dda2222c1bf0d3399.tar.gz
perlweeklychallenge-club-a42c096a9168065b7f35322dda2222c1bf0d3399.tar.bz2
perlweeklychallenge-club-a42c096a9168065b7f35322dda2222c1bf0d3399.zip
- Added solutions by Pete Houston.
-rw-r--r--challenge-126/pete-houston/perl/ch-1.pl87
-rw-r--r--challenge-126/pete-houston/perl/ch-2.pl56
-rw-r--r--stats/pwc-current.json183
-rw-r--r--stats/pwc-language-breakdown-summary.json42
-rw-r--r--stats/pwc-language-breakdown.json796
-rw-r--r--stats/pwc-leaders.json692
-rw-r--r--stats/pwc-summary-1-30.json38
-rw-r--r--stats/pwc-summary-121-150.json48
-rw-r--r--stats/pwc-summary-151-180.json104
-rw-r--r--stats/pwc-summary-181-210.json56
-rw-r--r--stats/pwc-summary-211-240.json102
-rw-r--r--stats/pwc-summary-31-60.json38
-rw-r--r--stats/pwc-summary-61-90.json110
-rw-r--r--stats/pwc-summary-91-120.json52
-rw-r--r--stats/pwc-summary.json60
15 files changed, 1311 insertions, 1153 deletions
diff --git a/challenge-126/pete-houston/perl/ch-1.pl b/challenge-126/pete-houston/perl/ch-1.pl
new file mode 100644
index 0000000000..445a905738
--- /dev/null
+++ b/challenge-126/pete-houston/perl/ch-1.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 12601.pl
+#
+# USAGE: ./12601.pl [ -b | -m ] N
+#
+# DESCRIPTION: Output total number of integers between 1 and N which
+# do not have a digit "1".
+#
+# OPTIONS: -b will use the slow brute-force algorithm instead.
+# -m will use the equally slow smarter_count algorithm.
+# Specifying neither uses the fast "calc" algorithm.
+# REQUIREMENTS: Getopt::Long::Modern
+# NOTES: The default (fast "calc") algorithm is recommended for
+# any serious use. The others are there just for reference
+# and validation.
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 16/08/21
+#===============================================================================
+
+use strict;
+use warnings;
+use Getopt::Long::Modern;
+
+GetOptions (b => \my $brute, m => \my $modified);
+my $n = shift;
+die "Argument must be a natural number" unless $n =~ /^[1-9][0-9]*$/;
+
+my $count =
+ $brute ? brute_force_count ($n) :
+ $modified ? smarter_count ($n) :
+ calc ($n);
+print "$count\n";
+
+# Maths FTW!
+sub calc {
+ my $upper = shift;
+
+ my $power = length ($upper) - 1;
+ my $rest = $upper % 10 ** $power;
+ my $first = int ($upper / 10 ** $power);
+
+ my $tot = calc ($rest) if $rest && $first != 1;
+
+ # for a number of 10^n answer is demonstrably 9^n - 1.
+ if ($first > 1) {
+ $tot += ($first - 1) * (9 ** $power);
+ } else {
+ $tot += (9 ** $power - 1);
+ }
+ return $tot;
+}
+
+# Starts to grind beyond 10^7
+sub brute_force_count {
+ my $upper = shift;
+ my $tot = 0;
+
+ for (1 .. $upper) {
+ $tot++ if -1 == index $_, '1';
+ }
+
+ return $tot;
+}
+
+# Not actually much faster than brute_force_count
+sub smarter_count {
+ my $upper = shift;
+ my $tot = 0;
+
+ my $c = 1;
+ while ($c <= $upper) {
+ my $place = index $c, '1';
+ if ($place == -1) {
+ $tot++;
+ $c++;
+ } else {
+ $c += 10 ** (length ($c) - $place - 1);
+ }
+ }
+
+ return $tot;
+}
+
diff --git a/challenge-126/pete-houston/perl/ch-2.pl b/challenge-126/pete-houston/perl/ch-2.pl
new file mode 100644
index 0000000000..87e7990662
--- /dev/null
+++ b/challenge-126/pete-houston/perl/ch-2.pl
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 12602.pl
+#
+# USAGE: ./12602.pl < INFILE
+#
+# DESCRIPTION: Output minesweeper grid based on INFILE.
+#
+# REQUIREMENTS: Input must be on STDIN
+# NOTES: Input file should consist of a rectangular grid with
+# values of "x" or "*" only. Any other characters will be
+# ignored, so use as much/little in-line whitespace as you
+# like. Each line of input must have the same number of
+# valid characters otherwise an exception will be thrown.
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 16/08/21
+#===============================================================================
+
+use strict;
+use warnings;
+
+my @grid;
+my $len;
+
+while ($_ = <STDIN>) {
+ my @row = /([*x])/g;
+ if (defined $len) {
+ die "Non-rectangular grid" unless $#row == $len;
+ } else {
+ $len = $#row;
+ }
+ push @grid, \@row;
+}
+
+for my $r (0..$#grid) {
+ for my $c (0..$len) {
+ next if $grid[$r][$c] eq 'x'; # Bombs are bombs
+
+ # Count the neighbours
+ my $sum = 0;
+ for my $y ($r - 1 .. $r + 1) {
+ for my $x ($c - 1 .. $c + 1) {
+ $sum++ if
+ $y >= 0 && $y <= $#grid &&
+ $x >= 0 && $x <= $len &&
+ ($y != $r || $x != $c) &&
+ $grid[$y][$x] eq 'x';
+ }
+ }
+ $grid[$r][$c] = $sum;
+ }
+ print "@{$grid[$r]}\n";
+}
diff --git a/stats/pwc-current.json b/stats/pwc-current.json
index af6a64ae2e..c10db3aded 100644
--- a/stats/pwc-current.json
+++ b/stats/pwc-current.json
@@ -2,7 +2,6 @@
"drilldown" : {
"series" : [
{
- "name" : "Andinus",
"data" : [
[
"Raku",
@@ -13,27 +12,28 @@
2
]
],
+ "name" : "Andinus",
"id" : "Andinus"
},
{
- "id" : "Andrew Shitov",
- "name" : "Andrew Shitov",
"data" : [
[
"Raku",
1
]
- ]
+ ],
+ "name" : "Andrew Shitov",
+ "id" : "Andrew Shitov"
},
{
- "id" : "Cristina Heredia",
+ "name" : "Cristina Heredia",
"data" : [
[
"Perl",
1
]
],
- "name" : "Cristina Heredia"
+ "id" : "Cristina Heredia"
},
{
"name" : "Dave Jacoby",
@@ -93,16 +93,15 @@
},
{
"id" : "Konstantinos Giannakakis",
- "name" : "Konstantinos Giannakakis",
"data" : [
[
"Perl",
2
]
- ]
+ ],
+ "name" : "Konstantinos Giannakakis"
},
{
- "id" : "Laurent Rosenfeld",
"name" : "Laurent Rosenfeld",
"data" : [
[
@@ -117,10 +116,11 @@
"Blog",
1
]
- ]
+ ],
+ "id" : "Laurent Rosenfeld"
},
{
- "name" : "Luca Ferrari",
+ "id" : "Luca Ferrari",
"data" : [
[
"Raku",
@@ -131,51 +131,59 @@
2
]
],
- "id" : "Luca Ferrari"
+ "name" : "Luca Ferrari"
},
{
- "id" : "Mark Anderson",
"name" : "Mark Anderson",
"data" : [
[
"Raku",
2
]
- ]
+ ],
+ "id" : "Mark Anderson"
},
{
- "id" : "Matthew Neleigh",
"data" : [
[
"Perl",
2
]
],
- "name" : "Matthew Neleigh"
+ "name" : "Matthew Neleigh",
+ "id" : "Matthew Neleigh"
},
{
- "name" : "Olivier Delouya",
+ "id" : "Olivier Delouya",
"data" : [
[
"Perl",
1
]
],
- "id" : "Olivier Delouya"
+ "name" : "Olivier Delouya"
},
{
- "name" : "Paul Fajman",
"data" : [
[
"Perl",
2
]
],
- "id" : "Paul Fajman"
+ "id" : "Paul Fajman",
+ "name" : "Paul Fajman"
+ },
+ {
+ "data" : [
+ [
+ "Perl",
+ 2
+ ]
+ ],
+ "id" : "Pete Houston",
+ "name" : "Pete Houston"
},
{
- "id" : "Roger Bell_West",
- "name" : "Roger Bell_West",
"data" : [
[
"Perl",
@@ -189,11 +197,11 @@
"Blog",
1
]
- ]
+ ],
+ "id" : "Roger Bell_West",
+ "name" : "Roger Bell_West"
},
{
- "id" : "Simon Green",
- "name" : "Simon Green",
"data" : [
[
"Perl",
@@ -203,31 +211,32 @@
"Blog",
1
]
- ]
+ ],
+ "id" : "Simon Green",
+ "name" : "Simon Green"
},
{
- "name" : "Simon Proctor",
+ "id" : "Simon Proctor",
"data" : [
[
"Raku",
2
]
],
- "id" : "Simon Proctor"
+ "name" : "Simon Proctor"
},
{
+ "id" : "Steven Wilson",
"data" : [
[
"Perl",
1
]
],
- "name" : "Steven Wilson",
- "id" : "Steven Wilson"
+ "name" : "Steven Wilson"
},
{
"id" : "Stuart Little",
- "name" : "Stuart Little",
"data" : [
[
"Perl",
@@ -237,10 +246,10 @@
"Raku",
2
]
- ]
+ ],
+ "name" : "Stuart Little"
},
{
- "name" : "Ulrich Rieke",
"data" : [
[
"Perl",
@@ -251,9 +260,11 @@
2
]
],
- "id" : "Ulrich Rieke"
+ "id" : "Ulrich Rieke",
+ "name" : "Ulrich Rieke"
},
{
+ "id" : "W. Luis Mochan",
"data" : [
[
"Perl",
@@ -264,29 +275,29 @@
1
]
],
- "name" : "W. Luis Mochan",
- "id" : "W. Luis Mochan"
+ "name" : "W. Luis Mochan"
}
]
},
- "title" : {
- "text" : "The Weekly Challenge - 126"
- },
- "legend" : {
- "enabled" : 0
+ "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
},
"series" : [
{
+ "colorByPoint" : 1,
+ "name" : "The Weekly Challenge - 126",
"data" : [
{
- "drilldown" : "Andinus",
+ "y" : 4,
"name" : "Andinus",
- "y" : 4
+ "drilldown" : "Andinus"
},
{
+ "y" : 1,
"name" : "Andrew Shitov",
- "drilldown" : "Andrew Shitov",
- "y" : 1
+ "drilldown" : "Andrew Shitov"
},
{
"name" : "Cristina Heredia",
@@ -299,33 +310,33 @@
"y" : 3
},
{
+ "y" : 6,
"drilldown" : "Flavio Poletti",
- "name" : "Flavio Poletti",
- "y" : 6
+ "name" : "Flavio Poletti"
},
{
- "y" : 3,
+ "name" : "James Smith",
"drilldown" : "James Smith",
- "name" : "James Smith"
+ "y" : 3
},
{
- "y" : 2,
+ "drilldown" : "Jorg Sommrey",
"name" : "Jorg Sommrey",
- "drilldown" : "Jorg Sommrey"
+ "y" : 2
},
{
- "y" : 2,
+ "name" : "Konstantinos Giannakakis",
"drilldown" : "Konstantinos Giannakakis",
- "name" : "Konstantinos Giannakakis"
+ "y" : 2
},
{
+ "y" : 5,
"name" : "Laurent Rosenfeld",
- "drilldown" : "Laurent Rosenfeld",
- "y" : 5
+ "drilldown" : "Laurent Rosenfeld"
},
{
- "name" : "Luca Ferrari",
"drilldown" : "Luca Ferrari",
+ "name" : "Luca Ferrari",
"y" : 4
},
{
@@ -334,13 +345,13 @@
"y" : 2
},
{
- "drilldown" : "Matthew Neleigh",
+ "y" : 2,
"name" : "Matthew Neleigh",
- "y" : 2
+ "drilldown" : "Matthew Neleigh"
},
{
- "drilldown" : "Olivier Delouya",
"name" : "Olivier Delouya",
+ "drilldown" : "Olivier Delouya",
"y" : 1
},
{
@@ -349,14 +360,19 @@
"y" : 2
},
{
- "drilldown" : "Roger Bell_West",
+ "y" : 2,
+ "name" : "Pete Houston",
+ "drilldown" : "Pete Houston"
+ },
+ {
"name" : "Roger Bell_West",
+ "drilldown" : "Roger Bell_West",
"y" : 5
},
{
+ "y" : 3,
"drilldown" : "Simon Green",
- "name" : "Simon Green",
- "y" : 3
+ "name" : "Simon Green"
},
{
"drilldown" : "Simon Proctor",
@@ -379,41 +395,40 @@
"y" : 4
},
{
- "y" : 3,
+ "drilldown" : "W. Luis Mochan",
"name" : "W. Luis Mochan",
- "drilldown" : "W. Luis Mochan"
+ "y" : 3
}
- ],
- "colorByPoint" : 1,
- "name" : "The Weekly Challenge - 126"
+ ]
}
],
- "xAxis" : {
- "type" : "category"
- },
- "tooltip" : {
- "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>",
- "followPointer" : 1,
- "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>"
+ "chart" : {
+ "type" : "column"
},
- "subtitle" : {
- "text" : "[Champions: 21] Last updated at 2021-08-20 23:32:49 GMT"
+ "yAxis" : {
+ "title" : {
+ "text" : "Total Solutions"
+ }
},
"plotOptions" : {
"series" : {
"dataLabels" : {
- "enabled" : 1,
- "format" : "{point.y}"
+ "format" : "{point.y}",
+ "enabled" : 1
},
"borderWidth" : 0
}
},
- "chart" : {
- "type" : "column"
+ "legend" : {
+ "enabled" : 0
},
- "yAxis" : {
- "title" : {
- "text" : "Total Solutions"
- }
+ "title" : {
+ "text" : "The Weekly Challenge - 126"
+ },
+ "xAxis" : {
+ "type" : "category"
+ },
+ "subtitle" : {
+ "text" : "[Champions: 22] Last updated at 2021-08-20 23:43:24 GMT"
}
}
diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json
index 1bee46cdc1..3c5b2899e0 100644
--- a/stats/pwc-language-breakdown-summary.json
+++ b/stats/pwc-language-breakdown-summary.json
@@ -1,19 +1,28 @@
{
+ "subtitle" : {
+ "text" : "Last updated at 2021-08-20 23:43:24 GMT"
+ },
"legend" : {
"enabled" : "false"
},
- "title" : {
- "text" : "The Weekly Challenge Contributions [2019 - 2021]"
- },
"xAxis" : {
"labels" : {
"style" : {
- "fontFamily" : "Verdana, sans-serif",
- "fontSize" : "13px"
+ "fontSize" : "13px",
+ "fontFamily" : "Verdana, sans-serif"
}
},
"type" : "category"
},
+ "title" : {
+ "text" : "The Weekly Challenge Contributions [2019 - 2021]"
+ },
+ "tooltip" : {
+ "pointFormat" : "<b>{point.y:.0f}</b>"
+ },
+ "chart" : {
+ "type" : "column"
+ },
"series" : [
{
"data" : [
@@ -23,7 +32,7 @@
],
[
"Perl",
- 6016
+ 6018
],
[
"Raku",
@@ -32,32 +41,23 @@
],
"name" : "Contributions",
"dataLabels" : {
+ "align" : "right",
"format" : "{point.y:.0f}",
"rotation" : -90,
- "y" : 10,
"enabled" : "true",
- "align" : "right",
+ "color" : "#FFFFFF",
+ "y" : 10,
"style" : {
"fontSize" : "13px",
"fontFamily" : "Verdana, sans-serif"
- },
- "color" : "#FFFFFF"
+ }
}
}
],
- "chart" : {
- "type" : "column"
- },
- "tooltip" : {
- "pointFormat" : "<b>{point.y:.0f}</b>"
- },
- "subtitle" : {
- "text" : "Last updated at 2021-08-20 23:32:49 GMT"
- },
"yAxis" : {
- "min" : 0,
"title" : {
"text" : null
- }
+ },
+ "min" : 0
}
}
diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json
index 630e3a4716..20529135e3 100644
--- a/stats/pwc-language-breakdown.json
+++ b/stats/pwc-language-breakdown.json
@@ -21,7 +21,6 @@
},
{
"id" : "002",
- "name" : "002",
"data" : [
[
"Perl",
@@ -35,7 +34,8 @@
"Blog",
10
]
- ]
+ ],
+ "name" : "002"
},
{
"id" : "003",
@@ -74,7 +74,7 @@
"id" : "004"
},
{
- "name" : "005",
+ "id" : "005",
"data" : [
[
"Perl",
@@ -89,11 +89,9 @@
12
]
],
- "id" : "005"
+ "name" : "005"
},
{
- "id" : "006",
- "name" : "006",
"data" : [
[
"Perl",
@@ -107,10 +105,12 @@
"Blog",
7
]
- ]
+ ],
+ "id" : "006",
+ "name" : "006"
},
{
- "name" : "007",
+ "id" : "007",
"data" : [
[
"Perl",
@@ -125,7 +125,7 @@
10
]
],
- "id" : "007"
+ "name" : "007"
},
{
"data" : [
@@ -146,7 +146,7 @@
"id" : "008"
},
{
- "name" : "009",
+ "id" : "009",
"data" : [
[
"Perl",
@@ -161,11 +161,9 @@
13
]
],
- "id" : "009"
+ "name" : "009"
},
{
- "id" : "010",
- "name" : "010",
"data" : [
[
"Perl",
@@ -179,10 +177,12 @@
"Blog",
11
]
- ]
+ ],
+ "id" : "010",
+ "name" : "010"
},
{
- "id" : "011",
+ "name" : "011",
"data" : [
[
"Perl",
@@ -197,11 +197,10 @@
10
]
],
- "name" : "011"
+ "id" : "011"
},
{
"id" : "012",
- "name" : "012",
"data" : [
[
"Perl",
@@ -215,10 +214,10 @@
"Blog",
11
]
- ]
+ ],
+ "name" : "012"
},
{
- "name" : "013",
"data" : [
[
"Perl",
@@ -233,10 +232,11 @@
13
]
],
+ "name" : "013",
"id" : "013"
},
{
- "name" : "014",
+ "id" : "014",
"data" : [
[
"Perl",
@@ -251,10 +251,9 @@
15
]
],
- "id" : "014"
+ "name" : "014"
},
{
- "name" : "015",
"data" : [
[
"Perl",
@@ -269,10 +268,11 @@
15
]
],
- "id" : "015"
+ "id" : "015",
+ "name" : "015"
},
{
- "name" : "016",
+ "id" : "016",
"data" : [
[
"Perl",
@@ -287,10 +287,9 @@
12
]
],
- "id" : "016"
+ "name" : "016"
},
{
- "id" : "017",
"data" : [
[
"Perl",
@@ -305,11 +304,10 @@
12
]
],
+ "id" : "017",
"name" : "017"
},
{
- "id" : "018",
- "name" : "018",
"data" : [
[
"Perl",
@@ -323,11 +321,12 @@
"Blog",
14
]
- ]
+ ],
+ "id" : "018",
+ "name" : "018"
},
{
"id" : "019",
- "name" : "019",
"data" : [
[
"Perl",
@@ -341,9 +340,11 @@
"Blog",
13
]
- ]
+ ],
+ "name" : "019"
},
{
+ "name" : "020",
"data" : [
[
"Perl",
@@ -358,12 +359,9 @@
13
]
],
- "name" : "020",
"id" : "020"
},
{
- "id" : "021",
- "name" : "021",
"data" : [
[
"Perl",
@@ -377,10 +375,11 @@
"Blog",
10
]
- ]
+ ],
+ "name" : "021",
+ "id" : "021"
},
{
- "id" : "022",
"data" : [
[
"Perl",
@@ -395,11 +394,10 @@
10
]
],
- "name" : "022"
+ "name" : "022",
+ "id" : "022"
},
{
- "id" : "023",
- "name" : "023",
"data" : [
[
"Perl",
@@ -413,11 +411,11 @@
"Blog",
12
]
- ]
+ ],
+ "id" : "023",
+ "name" : "023"
},
{
- "id" : "024",
- "name" : "024",
"data" : [
[
"Perl",
@@ -431,7 +429,9 @@
"Blog",
11
]
- ]
+ ],
+ "id" : "024",
+ "name" : "024"
},
{
"name" : "025",
@@ -452,7 +452,6 @@
"id" : "025"
},
{
- "id" : "026",
"data" : [
[
"Perl",
@@ -467,6 +466,7 @@
10
]
],
+ "id" : "026",
"name" : "026"
},
{
@@ -484,11 +484,11 @@
9
]
],
- "name" : "027",
- "id" : "027"
+ "id" : "027",
+ "name" : "027"
},
{
- "id" : "028",
+ "name" : "028",
"data" : [
[
"Perl",
@@ -503,9 +503,10 @@
9
]
],
- "name" : "028"
+ "id" : "028"
},
{
+ "id" : "029",
"data" : [
[
"Perl",
@@ -520,11 +521,10 @@
12
]
],
- "name" : "029",
- "id" : "029"
+ "name" : "029"
},
{
- "name" : "030",
+ "id" : "030",
"data" : [
[
"Perl",
@@ -539,10 +539,10 @@
10
]
],
- "id" : "030"
+ "name" : "030"
},
{
- "id" : "031",
+ "name" : "031",
"data" : [
[
"Perl",
@@ -557,7 +557,7 @@
9
]
],
- "name" : "031"
+ "id" : "031"
},
{
"data" : [
@@ -574,11 +574,10 @@
10
]
],
- "name" : "032",
- "id" : "032"
+ "id" : "032",
+ "name" : "032"
},
{
- "name" : "033",
"data" : [
[
"Perl",
@@ -593,9 +592,11 @@
10
]
],
+ "name" : "033",
"id" : "033"
},
{
+ "id" : "034",
"data" : [
[
"Perl",
@@ -610,12 +611,10 @@
11
]
],
- "name" : "034",
- "id" : "034"
+ "name" : "034"
},
{
"id" : "035",
- "name" : "035",
"data" : [
[
"Perl",
@@ -629,10 +628,10 @@
"Blog",
9
]
- ]
+ ],
+ "name" : "035"
},
{
- "name" : "036",
"data" : [
[
"Perl",
@@ -647,11 +646,11 @@
11
]
],
+ "name" : "036",
"id" : "036"
},
{
"id" : "037",
- "name" : "037",
"data" : [
[
"Perl",
@@ -665,10 +664,10 @@
"Blog",
9
]
- ]
+ ],
+ "name" : "037"
},
{
- "name" : "038",
"data" : [
[
"Perl",
@@ -683,11 +682,11 @@
12
]
],
- "id" : "038"
+ "id" : "038",
+ "name" : "038"