aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2021-06-05 15:33:41 +0200
committerarnesom <arne@bbop.org>2021-06-05 15:33:41 +0200
commit4d6b3fadfb006aa95a660549160100180e5db14d (patch)
tree8fc009c06f55051d5ad91378299eca0961fbf090
parent373a97f7ee737cbd8d3e8d87a96b6ae0dec388b5 (diff)
downloadperlweeklychallenge-club-4d6b3fadfb006aa95a660549160100180e5db14d.tar.gz
perlweeklychallenge-club-4d6b3fadfb006aa95a660549160100180e5db14d.tar.bz2
perlweeklychallenge-club-4d6b3fadfb006aa95a660549160100180e5db14d.zip
Arne Sommer
-rw-r--r--challenge-115/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-115/arne-sommer/perl/ch-1.pl50
-rwxr-xr-xchallenge-115/arne-sommer/perl/ch-2.pl29
-rwxr-xr-xchallenge-115/arne-sommer/perl/largest-multiple-perl29
-rwxr-xr-xchallenge-115/arne-sommer/perl/string-chain-perl50
-rwxr-xr-xchallenge-115/arne-sommer/raku/ch-1.raku35
-rwxr-xr-xchallenge-115/arne-sommer/raku/ch-2.raku9
-rwxr-xr-xchallenge-115/arne-sommer/raku/largest-multiple9
-rwxr-xr-xchallenge-115/arne-sommer/raku/string-chain35
-rwxr-xr-xchallenge-115/arne-sommer/raku/string-chain-7bridges23
-rwxr-xr-xchallenge-115/arne-sommer/raku/string-chain-7bridges-duplicates25
11 files changed, 295 insertions, 0 deletions
diff --git a/challenge-115/arne-sommer/blog.txt b/challenge-115/arne-sommer/blog.txt
new file mode 100644
index 0000000000..9682b358f8
--- /dev/null
+++ b/challenge-115/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/hamilton-unchained.html
diff --git a/challenge-115/arne-sommer/perl/ch-1.pl b/challenge-115/arne-sommer/perl/ch-1.pl
new file mode 100755
index 0000000000..22a6b0ba97
--- /dev/null
+++ b/challenge-115/arne-sommer/perl/ch-1.pl
@@ -0,0 +1,50 @@
+#! /usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use Getopt::Long;
+use Algorithm::Combinatorics 'permutations';
+use feature 'signatures';
+
+no warnings qw(experimental::signatures);
+
+my $verbose = 0;
+
+GetOptions("verbose" => \$verbose);
+
+die "At least two strings" unless @ARGV > 1;
+
+for my $list (permutations(\@ARGV))
+{
+ my @perm = @$list;
+
+ say ": perm: " . join(", ", @perm) if $verbose;
+
+ if (is_circle(@perm))
+ {
+ say 1;
+ exit;
+ }
+}
+
+say 0;
+
+sub is_circle (@list)
+{
+ my $first = shift(@list);
+ my $first_start = substr($first, 0,1);
+ my $second;
+
+ while (@list)
+ {
+ $second = shift(@list);
+ return 0 if substr($first,-1,1) ne substr($second,0,1);
+ $first = $second;
+ }
+
+ return 1 if $first_start eq substr($second,-1,1);
+ return 0;
+}
+
+
diff --git a/challenge-115/arne-sommer/perl/ch-2.pl b/challenge-115/arne-sommer/perl/ch-2.pl
new file mode 100755
index 0000000000..c2dce1668d
--- /dev/null
+++ b/challenge-115/arne-sommer/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#! /usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use Getopt::Long;
+use Algorithm::Combinatorics 'permutations';
+
+my $verbose = 0;
+
+GetOptions("verbose" => \$verbose);
+
+my @all;
+
+for my $list (permutations(\@ARGV))
+{
+ my @candidate = @$list;
+ my $value = join("", @candidate);
+
+ next unless $value =~ /[02468]$/;
+
+ push(@all, $value);
+}
+
+@all = reverse sort @all;
+
+say ": " . join(", ", @all) if $verbose && @all;
+
+say $all[0] if $all[0] && $all[0] != 0;
diff --git a/challenge-115/arne-sommer/perl/largest-multiple-perl b/challenge-115/arne-sommer/perl/largest-multiple-perl
new file mode 100755
index 0000000000..c2dce1668d
--- /dev/null
+++ b/challenge-115/arne-sommer/perl/largest-multiple-perl
@@ -0,0 +1,29 @@
+#! /usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use Getopt::Long;
+use Algorithm::Combinatorics 'permutations';
+
+my $verbose = 0;
+
+GetOptions("verbose" => \$verbose);
+
+my @all;
+
+for my $list (permutations(\@ARGV))
+{
+ my @candidate = @$list;
+ my $value = join("", @candidate);
+
+ next unless $value =~ /[02468]$/;
+
+ push(@all, $value);
+}
+
+@all = reverse sort @all;
+
+say ": " . join(", ", @all) if $verbose && @all;
+
+say $all[0] if $all[0] && $all[0] != 0;
diff --git a/challenge-115/arne-sommer/perl/string-chain-perl b/challenge-115/arne-sommer/perl/string-chain-perl
new file mode 100755
index 0000000000..22a6b0ba97
--- /dev/null
+++ b/challenge-115/arne-sommer/perl/string-chain-perl
@@ -0,0 +1,50 @@
+#! /usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use Getopt::Long;
+use Algorithm::Combinatorics 'permutations';
+use feature 'signatures';
+
+no warnings qw(experimental::signatures);
+
+my $verbose = 0;
+
+GetOptions("verbose" => \$verbose);
+
+die "At least two strings" unless @ARGV > 1;
+
+for my $list (permutations(\@ARGV))
+{
+ my @perm = @$list;
+
+ say ": perm: " . join(", ", @perm) if $verbose;
+
+ if (is_circle(@perm))
+ {
+ say 1;
+ exit;
+ }
+}
+
+say 0;
+
+sub is_circle (@list)
+{
+ my $first = shift(@list);
+ my $first_start = substr($first, 0,1);
+ my $second;
+
+ while (@list)
+ {
+ $second = shift(@list);
+ return 0 if substr($first,-1,1) ne substr($second,0,1);
+ $first = $second;
+ }
+
+ return 1 if $first_start eq substr($second,-1,1);
+ return 0;
+}
+
+
diff --git a/challenge-115/arne-sommer/raku/ch-1.raku b/challenge-115/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..1922b29dd2
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,35 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@S where @S.elems > 1, :v(:$verbose), :n(:$no-duplicates));
+
+die "Non-unique string not allowed" if $no-duplicates && @S.elems != @S.unique.elems;
+
+for @S.permutations -> @perm
+{
+ say ": perm: { @perm.join(", ") }" if $verbose;
+
+ if is-circle(@perm)
+ {
+ say 1;
+ exit;
+ }
+}
+
+say 0;
+
+sub is-circle (@list is copy)
+{
+ my $first = @list.shift;
+ my $first-start = $first.substr(0,1);
+ my $second;
+
+ while @list
+ {
+ $second = @list.shift;
+ return False if $first.substr(*-1,1) ne $second.substr(0,1);
+ $first = $second;
+ }
+
+ return True if $first-start eq $second.substr(*-1,1);
+ return False;
+}
diff --git a/challenge-115/arne-sommer/raku/ch-2.raku b/challenge-115/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..5abea60e99
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,9 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@N where @N.elems > 0 && all(@N) == any(0..9), :v(:$verbose));
+
+my @all = @N.permutations>>.join.grep(* ~~ / <[02468]> $/).sort.reverse;
+
+say ": { @all.join(", ") }" if $verbose && @all;
+
+say @all[0] if @all[0] && @all[0] != 0;
diff --git a/challenge-115/arne-sommer/raku/largest-multiple b/challenge-115/arne-sommer/raku/largest-multiple
new file mode 100755
index 0000000000..5abea60e99
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/largest-multiple
@@ -0,0 +1,9 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@N where @N.elems > 0 && all(@N) == any(0..9), :v(:$verbose));
+
+my @all = @N.permutations>>.join.grep(* ~~ / <[02468]> $/).sort.reverse;
+
+say ": { @all.join(", ") }" if $verbose && @all;
+
+say @all[0] if @all[0] && @all[0] != 0;
diff --git a/challenge-115/arne-sommer/raku/string-chain b/challenge-115/arne-sommer/raku/string-chain
new file mode 100755
index 0000000000..1922b29dd2
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/string-chain
@@ -0,0 +1,35 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@S where @S.elems > 1, :v(:$verbose), :n(:$no-duplicates));
+
+die "Non-unique string not allowed" if $no-duplicates && @S.elems != @S.unique.elems;
+
+for @S.permutations -> @perm
+{
+ say ": perm: { @perm.join(", ") }" if $verbose;
+
+ if is-circle(@perm)
+ {
+ say 1;
+ exit;
+ }
+}
+
+say 0;
+
+sub is-circle (@list is copy)
+{
+ my $first = @list.shift;
+ my $first-start = $first.substr(0,1);
+ my $second;
+
+ while @list
+ {
+ $second = @list.shift;
+ return False if $first.substr(*-1,1) ne $second.substr(0,1);
+ $first = $second;
+ }
+
+ return True if $first-start eq $second.substr(*-1,1);
+ return False;
+}
diff --git a/challenge-115/arne-sommer/raku/string-chain-7bridges b/challenge-115/arne-sommer/raku/string-chain-7bridges
new file mode 100755
index 0000000000..0e59cec0c0
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/string-chain-7bridges
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@S where @S.elems > 0);
+
+die "Non-unique string not allowed" if @S.elems != @S.unique.elems;
+
+for @S -> $elem
+{
+ say "$elem: $elem";
+}
+
+for @S -> $first
+{
+ for @S -> $second
+ {
+ next if $second eq $first;
+
+ if $second.substr(*-1,1) eq $first.substr(0,1)
+ {
+ say "$second>$first {$first.substr(0,1)}";
+ }
+ }
+}
diff --git a/challenge-115/arne-sommer/raku/string-chain-7bridges-duplicates b/challenge-115/arne-sommer/raku/string-chain-7bridges-duplicates
new file mode 100755
index 0000000000..e577aabdc0
--- /dev/null
+++ b/challenge-115/arne-sommer/raku/string-chain-7bridges-duplicates
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@S where @S.elems > 0);
+
+my %elems;
+my $id = 0;
+
+for @S -> $elem
+{
+ %elems{++$id} = $elem;
+ say "$id: $elem";
+}
+
+for 1 .. $id -> $first
+{
+ for 1 .. $id -> $second
+ {
+ next if $second eq $first;
+
+ if %elems{$second}.substr(*-1,1) eq %elems{$first}.substr(0,1)
+ {
+ say "$second>$first {%elems{$first}.substr(0,1)}";
+ }
+ }
+}