aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-06-30 00:44:09 +0200
committerAbigail <abigail@abigail.be>2021-06-30 00:44:09 +0200
commit20c14072c2b9a491fd414d275b6c64c6fec8e62f (patch)
tree8de976c75da6f68a0c9ee91809dcc3a340358fdc
parenta6180cd9e375d5f36d77f7a2aac2650d5c642058 (diff)
parent551f8dc93afa46a598644f62e74e67cdae6f0c28 (diff)
downloadperlweeklychallenge-club-20c14072c2b9a491fd414d275b6c64c6fec8e62f.tar.gz
perlweeklychallenge-club-20c14072c2b9a491fd414d275b6c64c6fec8e62f.tar.bz2
perlweeklychallenge-club-20c14072c2b9a491fd414d275b6c64c6fec8e62f.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-rw-r--r--challenge-012/paulo-custodio/c/ch-1.c51
-rw-r--r--challenge-012/paulo-custodio/cpp/ch-1.cpp50
-rw-r--r--challenge-012/paulo-custodio/t/test-1.yaml5
-rw-r--r--challenge-012/paulo-custodio/t/test-2.yaml15
-rw-r--r--challenge-012/paulo-custodio/test.pl39
-rw-r--r--challenge-115/simon-proctor/raku/ch-2-2.raku71
-rw-r--r--challenge-118/james-smith/README.md149
-rw-r--r--challenge-118/james-smith/perl/ch-2-using-precomputed-distances.pl6
-rw-r--r--challenge-118/polettix/perl/ch-2.pl68
-rw-r--r--challenge-119/dave-cross/perl/ch-1.pl17
-rw-r--r--challenge-119/dave-cross/perl/ch-2.pl43
-rw-r--r--challenge-119/dave-jacoby/blog.txt1
-rw-r--r--challenge-119/dave-jacoby/node/ch-1.js23
-rw-r--r--challenge-119/dave-jacoby/node/ch-2.js51
-rw-r--r--challenge-119/dave-jacoby/perl/ch-1.pl24
-rw-r--r--challenge-119/dave-jacoby/perl/ch-2.pl54
-rw-r--r--challenge-119/james-smith/README.md484
-rw-r--r--challenge-119/james-smith/blog.txt1
-rw-r--r--challenge-119/james-smith/javascript/ch-1.js9
-rw-r--r--challenge-119/james-smith/perl/ch-1.pl21
-rw-r--r--challenge-119/james-smith/perl/ch-2.pl106
-rw-r--r--challenge-119/james-smith/php/ch-1.php13
-rw-r--r--challenge-119/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-119/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-119/luca-ferrari/raku/ch-1.p620
-rw-r--r--challenge-119/luca-ferrari/raku/ch-2.p617
-rw-r--r--challenge-119/mark-anderson/raku/ch-1.raku12
-rw-r--r--challenge-119/mark-anderson/raku/ch-2.raku13
-rw-r--r--challenge-119/polettix/blog.txt1
-rw-r--r--challenge-119/polettix/blog1.txt1
-rw-r--r--challenge-119/polettix/perl/ch-1.pl5
-rw-r--r--challenge-119/polettix/perl/ch-2.pl42
-rw-r--r--challenge-119/polettix/raku/ch-1.raku5
-rw-r--r--challenge-119/polettix/raku/ch-2.raku33
-rwxr-xr-xchallenge-119/roger-bell-west/perl/ch-1.pl14
-rwxr-xr-xchallenge-119/roger-bell-west/perl/ch-2.pl23
-rwxr-xr-xchallenge-119/roger-bell-west/python/ch-1.py18
-rwxr-xr-xchallenge-119/roger-bell-west/python/ch-2.py27
-rwxr-xr-xchallenge-119/roger-bell-west/raku/ch-1.p612
-rwxr-xr-xchallenge-119/roger-bell-west/raku/ch-2.p621
-rwxr-xr-xchallenge-119/roger-bell-west/ruby/ch-1.rb20
-rwxr-xr-xchallenge-119/roger-bell-west/ruby/ch-2.rb30
-rwxr-xr-xchallenge-119/roger-bell-west/rust/ch-1.rs16
-rw-r--r--challenge-119/roger-bell-west/rust/ch-2.rs30
-rw-r--r--challenge-119/sgreen/README.md4
-rw-r--r--challenge-119/sgreen/blog.txt1
-rwxr-xr-xchallenge-119/sgreen/perl/ch-1.pl18
-rwxr-xr-xchallenge-119/sgreen/perl/ch-2.pl22
-rw-r--r--challenge-119/simon-proctor/raku/ch-1.raku18
-rw-r--r--challenge-119/simon-proctor/raku/ch-2.raku18
-rwxr-xr-xchallenge-119/steven-wilson/perl/ch-1.pl14
-rwxr-xr-xchallenge-119/steven-wilson/perl/ch-2.pl27
-rwxr-xr-xchallenge-119/steven-wilson/python/ch-1.py9
-rw-r--r--challenge-119/steven-wilson/python/ch-2.py24
-rwxr-xr-xchallenge-119/stuart-little/haskell/ch-1.hs19
-rwxr-xr-xchallenge-119/stuart-little/haskell/ch-2.hs18
-rwxr-xr-xchallenge-119/stuart-little/node/ch-1.js5
-rwxr-xr-xchallenge-119/stuart-little/node/ch-2.js13
-rwxr-xr-xchallenge-119/stuart-little/perl/ch-1.pl7
-rwxr-xr-xchallenge-119/stuart-little/perl/ch-2.pl19
-rwxr-xr-xchallenge-119/stuart-little/python/ch-1.py7
-rwxr-xr-xchallenge-119/stuart-little/python/ch-2.py17
-rwxr-xr-xchallenge-119/stuart-little/raku/ch-1.raku6
-rwxr-xr-xchallenge-119/stuart-little/raku/ch-2.raku17
-rw-r--r--challenge-119/ulrich-rieke/cpp/ch-2.cpp34
-rw-r--r--challenge-119/ulrich-rieke/perl/ch-1.pl53
-rw-r--r--challenge-119/ulrich-rieke/perl/ch-2.pl42
-rw-r--r--challenge-119/ulrich-rieke/raku/ch-1.raku37
-rw-r--r--challenge-119/ulrich-rieke/raku/ch-2.raku36
-rw-r--r--challenge-119/vinod-k/perl/ch-1.pl15
-rw-r--r--challenge-119/wlmb/blog.txt1
-rwxr-xr-xchallenge-119/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-119/wlmb/perl/ch-2.pl32
-rw-r--r--challenge-119/ziameraj16/README.md20
-rw-r--r--challenge-119/ziameraj16/java/SwapNibbles.java23
-rw-r--r--stats/pwc-challenge-118.json605
-rw-r--r--stats/pwc-current.json557
-rw-r--r--stats/pwc-language-breakdown-summary.json86
-rw-r--r--stats/pwc-language-breakdown.json863
-rw-r--r--stats/pwc-leaders.json546
-rw-r--r--stats/pwc-summary-1-30.json42
-rw-r--r--stats/pwc-summary-121-150.json120
-rw-r--r--stats/pwc-summary-151-180.json96
-rw-r--r--stats/pwc-summary-181-210.json128
-rw-r--r--stats/pwc-summary-211-240.json50
-rw-r--r--stats/pwc-summary-31-60.json36
-rw-r--r--stats/pwc-summary-61-90.json66
-rw-r--r--stats/pwc-summary-91-120.json110
-rw-r--r--stats/pwc-summary.json534
89 files changed, 3824 insertions, 2271 deletions
diff --git a/challenge-012/paulo-custodio/c/ch-1.c b/challenge-012/paulo-custodio/c/ch-1.c
new file mode 100644
index 0000000000..967109929d
--- /dev/null
+++ b/challenge-012/paulo-custodio/c/ch-1.c
@@ -0,0 +1,51 @@
+/*
+Challenge 012
+
+Challenge #1
+The numbers formed by adding one to the products of the smallest primes are
+called the Euclid Numbers (see wiki). Write a script that finds the smallest
+Euclid Number that is not prime. This challenge was proposed by
+Laurent Rosenfeld.
+*/
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+bool is_prime(int n) {
+ if (n <= 1)
+ return false;
+ if (n <= 3)
+ return true;
+ if ((n % 2) == 0 || (n % 3) == 0)
+ return false;
+ for (int i = 5; i * i <= n; i += 6)
+ if ((n % i) == 0 || (n % (i + 2)) == 0)
+ return false;
+ return true;
+}
+
+int next_prime(int n) {
+ if (n <= 1)
+ return 2;
+ do {
+ n++;
+ } while (!is_prime(n));
+ return n;
+}
+
+int next_euclid(void) {
+ static int prime = 1;
+ static int prime_prod = 1;
+
+ prime = next_prime(prime);
+ prime_prod *= prime;
+ return prime_prod + 1;
+}
+
+int main(void) {
+ int euclid;
+ while (is_prime(euclid = next_euclid()))
+ ;
+ printf("%d\n", euclid);
+}
diff --git a/challenge-012/paulo-custodio/cpp/ch-1.cpp b/challenge-012/paulo-custodio/cpp/ch-1.cpp
new file mode 100644
index 0000000000..b18ecaaa19
--- /dev/null
+++ b/challenge-012/paulo-custodio/cpp/ch-1.cpp
@@ -0,0 +1,50 @@
+/*
+Challenge 012
+
+Challenge #1
+The numbers formed by adding one to the products of the smallest primes are
+called the Euclid Numbers (see wiki). Write a script that finds the smallest
+Euclid Number that is not prime. This challenge was proposed by
+Laurent Rosenfeld.
+*/
+
+#include <iostream>
+using namespace std;
+
+bool is_prime(int n) {
+ if (n <= 1)
+ return false;
+ if (n <= 3)
+ return true;
+ if ((n % 2) == 0 || (n % 3) == 0)
+ return false;
+ for (int i = 5; i * i <= n; i += 6)
+ if ((n % i) == 0 || (n % (i + 2)) == 0)
+ return false;
+ return true;
+}
+
+int next_prime(int n) {
+ if (n <= 1)
+ return 2;
+ do {
+ n++;
+ } while (!is_prime(n));
+ return n;
+}
+
+int next_euclid(void) {
+ static int prime = 1;
+ static int prime_prod = 1;
+
+ prime = next_prime(prime);
+ prime_prod *= prime;
+ return prime_prod + 1;
+}
+
+int main(void) {
+ int euclid;
+ while (is_prime(euclid = next_euclid()))
+ ;
+ cout << euclid << endl;
+}
diff --git a/challenge-012/paulo-custodio/t/test-1.yaml b/challenge-012/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..adaf9beab6
--- /dev/null
+++ b/challenge-012/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: 30031
diff --git a/challenge-012/paulo-custodio/t/test-2.yaml b/challenge-012/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..975c4a1c90
--- /dev/null
+++ b/challenge-012/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: / /a/b/c/d /a/b/cd /a/b/cc /a/b/c/d/e
+ input:
+ output: /a/b
+- setup:
+ cleanup:
+ args: ": :a:b:c:d :a:b:cd :a:b:cc :a:b:c:d:e"
+ input:
+ output: ":a:b"
+- setup:
+ cleanup:
+ args: / /b/c/d /a/b/c/d /a/b/cd /a/b/cc /a/b/c/d/e
+ input:
+ output:
diff --git a/challenge-012/paulo-custodio/test.pl b/challenge-012/paulo-custodio/test.pl
index db440a3a8f..ba6c37260b 100644
--- a/challenge-012/paulo-custodio/test.pl
+++ b/challenge-012/paulo-custodio/test.pl
@@ -1,37 +1,4 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use 5.030;
+#!/usr/bin/env perl
+use Modern::Perl;
use Test::More;
-
-is capture("perl perl/ch-1.pl"), "30031\n";
-
-is capture("perl perl/ch-2.pl / ".
- " /a/b/c/d ".
- " /a/b/cd ".
- " /a/b/cc ".
- " /a/b/c/d/e "), "/a/b\n";
-
-is capture("perl perl/ch-2.pl : ".
- " :a:b:c:d ".
- " :a:b:cd ".
- " :a:b:cc ".
- " :a:b:c:d:e "), ":a:b\n";
-
-is capture("perl perl/ch-2.pl / ".
- " /b/c/d ".
- " /a/b/c/d ".
- " /a/b/cd ".
- " /a/b/cc ".
- " /a/b/c/d/e "), "\n";
-
-done_testing;
-
-
-sub capture {
- my($cmd) = @_;
- my $out = `$cmd`;
- $out =~ s/[ \r\t]*\n/\n/g;
- return $out;
-}
+require '../../challenge-001/paulo-custodio/test.pl';
diff --git a/challenge-115/simon-proctor/raku/ch-2-2.raku b/challenge-115/simon-proctor/raku/ch-2-2.raku
new file mode 100644
index 0000000000..81ba11d805
--- /dev/null
+++ b/challenge-115/simon-proctor/raku/ch-2-2.raku
@@ -0,0 +1,71 @@
+#!/usr/bin/env raku
+
+#|( Given a triangle of height $N return the possible routes from the top
+ To the bottom right
+)
+multi sub MAIN(UInt $N) {
+ say traverse-triangle($N).join(", ");
+}
+
+multi sub MAIN("test") is hidden-from-USAGE {
+ use Test;
+ ok traverse-triangle(1) (==) <R LH>;
+ ok traverse-triangle(2) (==) <RR LHR LHLH LLHH RLH LRH>;
+}
+
+sub traverse-triangle( $size ) {
+ my %seen;
+ my @routes = ["R" x $size];
+
+ while (@routes) {
+ my @promises;
+ while (@routes && @promises.elems < 1000) {
+ my $route = shift @routes;
+ next if %seen{$route};
+ %seen{$route} = True;
+ given $route {
+ when /R/ {
+ @promises.push( start mod-right( $route ) );
+ proceed;
+ }
+ when /HL/ {
+ @promises.push( start mod-hl( $route ) );
+ }
+ }
+ }
+
+ await @promises;
+
+ for (@promises) -> $p {
+ for ( $p.result ) {
+ @routes.push( $_ ) if ! %seen{$_} && ($_ !(elem) @routes);
+ }
+ }
+
+ #note @routes.elems ~ ":" ~ @promises.elems ~ ":" ~ %seen.keys.elems;
+
+ }
+
+
+ return %seen.keys;
+}
+
+sub mod-right( Str $row ) {
+ my @out;
+ for (0..^$row.codes) -> $i {
+ if ( $row.substr($i,1) eq "R" ) {
+ @out.push( $row.substr(0,$i) ~ "LH" ~ $row.substr($i+1) );
+ }
+ }
+ return @out;
+}
+
+sub mod-hl( Str $row ) {
+ my @out;
+ for (0..^$row.codes-1) -> $i {
+ if ( $row.substr($i,2) eq "HL" ) {
+ @out.push( $row.substr(0,$i) ~ "R" ~ $row.substr($i+2) );
+ }
+ }
+ return @out;
+} \ No newline at end of file
diff --git a/challenge-118/james-smith/README.md b/challenge-118/james-smith/README.md
index 27cf024f18..ad9be11770 100644
--- a/challenge-118/james-smith/README.md
+++ b/challenge-118/james-smith/README.md
@@ -458,3 +458,152 @@ The time is now down to approximately 10 seconds.
[46, 53],
]
```
+
+## Task 2 - version 2 - using pre-computed distances.
+
+Reading CY's description using pre-computed distances I wanted to
+investigate how that worked.
+
+### Technique
+
+For any 2 squares we can compute the shortest distance in "steps"
+between them.
+
+Then we try all permutations of the order of the treasures (squares)
+to compute the optimal route. In theory we can pre-cache this
+information so that we don't have to calculate it every time we
+execute the script (as we could have with the transition matrix above).
+
+So we now have the following steps:
+
+ * Compute the transition matrix
+ * Compute the distance matrix - and store an example shortest route
+ between each pair of squares.
+ * Permute the points to compute a shortest route.
+
+### Stage 1
+
+See above for computing the transition matrix
+
+### Stage 2
+
+Computing the distance matrix.
+
+For each square (using our `0`..`63` notation) we generate
+an array of distances and routes. To do this we start by
+setting `$dist[$start][$start]` to `0` and
+`$route[$start][$start]` to `''`.
+We then repeatedly scan the board looking for increasing values
+of distance `0`, `1`, `2` etc, and finding squares we could jump
+to (that we already haven't) and set distance and routes for them.
+In this case I think the code is easier to understand than the
+description.
+
+By using our pre-computed transition matrix we not only remote
+the need for two levels of nested loops BUT also the need to
+perform the checks each time for stepping off the side of the board.
+
+```perl
+my $dist_maps = []; ## Map of distances betw
+my $route_maps = [];
+
+foreach my $start (0..63) {
+ my @dists = map { $_ == $start ? 0 : -1 } 0..63;
+ my @routes = map { '' } 0..63;
+ my $c = 1;
+ my $d = 0;
+ while($c<64) {
+ foreach my $x (0..63) {
+ next if $dists[$x] != $d;
+ foreach ( @{$trans->[$x]}) {
+ next if $T[$_]>=0;
+ $c++;
+ $dists[$_] = $d+1;
+ $routes[$_] = $routes[$x].chr$_;
+ }
+ }
+ $d++;
+ }
+