aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2023-01-22 22:08:49 +0100
committerarnesom <arne@bbop.org>2023-01-22 22:08:49 +0100
commit2e0c1a2e4ea53079d3f443352e59f579bab264f8 (patch)
tree6de8816a8057e5c01f979caed7675a76f8227b98
parent952f98a3d4e479992cd18e544ebb441a952f7159 (diff)
downloadperlweeklychallenge-club-2e0c1a2e4ea53079d3f443352e59f579bab264f8.tar.gz
perlweeklychallenge-club-2e0c1a2e4ea53079d3f443352e59f579bab264f8.tar.bz2
perlweeklychallenge-club-2e0c1a2e4ea53079d3f443352e59f579bab264f8.zip
Arne Sommer
-rw-r--r--challenge-200/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-200/arne-sommer/raku/arithmetic-slices33
-rwxr-xr-xchallenge-200/arne-sommer/raku/ch-1.raku33
-rwxr-xr-xchallenge-200/arne-sommer/raku/ch-2.raku39
-rwxr-xr-xchallenge-200/arne-sommer/raku/ss20039
-rwxr-xr-xchallenge-200/arne-sommer/raku/ss200-minus45
6 files changed, 190 insertions, 0 deletions
diff --git a/challenge-200/arne-sommer/blog.txt b/challenge-200/arne-sommer/blog.txt
new file mode 100644
index 0000000000..6afbaf05a5
--- /dev/null
+++ b/challenge-200/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/seven-angry-slices.html
diff --git a/challenge-200/arne-sommer/raku/arithmetic-slices b/challenge-200/arne-sommer/raku/arithmetic-slices
new file mode 100755
index 0000000000..e6517cff1f
--- /dev/null
+++ b/challenge-200/arne-sommer/raku/arithmetic-slices
@@ -0,0 +1,33 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@array where @array.elems && all(@array) ~~ /^<[0..9]>*$/, :v(:$verbose));
+
+my @slices;
+
+for 0 .. @array.end - 2 -> $i
+{
+ for $i + 2 .. @array.end -> $j
+ {
+ my $is-arislice = is-arislice(@array[$i..$j]);
+
+ say ": \@array[$i, $j] -> @array[$i..$j] { " -> arithmetic slice" if $is-arislice }" if $verbose;
+
+ @slices.push: "({ @array[$i..$j].join(",") })" if $is-arislice;
+
+ last unless $is-arislice;
+ }
+}
+
+say @slices ?? @slices.join(", ") !! "()";
+
+sub is-arislice(@array)
+{
+ my $diff = @array[1] - @array[0];
+
+ for 1 .. @array.end -1 -> $i
+ {
+ return False unless @array[$i+1] - @array[$i] == $diff;
+ }
+
+ return True;
+}
diff --git a/challenge-200/arne-sommer/raku/ch-1.raku b/challenge-200/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..e6517cff1f
--- /dev/null
+++ b/challenge-200/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,33 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@array where @array.elems && all(@array) ~~ /^<[0..9]>*$/, :v(:$verbose));
+
+my @slices;
+
+for 0 .. @array.end - 2 -> $i
+{
+ for $i + 2 .. @array.end -> $j
+ {
+ my $is-arislice = is-arislice(@array[$i..$j]);
+
+ say ": \@array[$i, $j] -> @array[$i..$j] { " -> arithmetic slice" if $is-arislice }" if $verbose;
+
+ @slices.push: "({ @array[$i..$j].join(",") })" if $is-arislice;
+
+ last unless $is-arislice;
+ }
+}
+
+say @slices ?? @slices.join(", ") !! "()";
+
+sub is-arislice(@array)
+{
+ my $diff = @array[1] - @array[0];
+
+ for 1 .. @array.end -1 -> $i
+ {
+ return False unless @array[$i+1] - @array[$i] == $diff;
+ }
+
+ return True;
+}
diff --git a/challenge-200/arne-sommer/raku/ch-2.raku b/challenge-200/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..e87e70a1e2
--- /dev/null
+++ b/challenge-200/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,39 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (UInt $int = 200, :v(:$verbose));
+
+my @truth = qw<abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg>;
+
+my @result;
+
+for $int.comb -> $digit
+{
+ say ":Digit: $digit -> @truth[$digit]" if $verbose;
+
+ my @matrix;
+
+ # (^7).map({ @matrix[$_] = (" " xx 7).Array; });
+ (^7).map({ @matrix[$_] = " ".comb.Array; });
+
+ @matrix[0] = ("-" xx 7).Array if @truth[$digit] ~~ /a/;
+ @matrix[3] = ("-" xx 7).Array if @truth[$digit] ~~ /g/;
+ @matrix[6] = ("-" xx 7).Array if @truth[$digit] ~~ /d/;
+
+ @matrix[1][0] = "|" if @truth[$digit] ~~ /f/;
+ @matrix[2][0] = "|" if @truth[$digit] ~~ /f/;
+
+ @matrix[1][6] = "|" if @truth[$digit] ~~ /b/;
+ @matrix[2][6] = "|" if @truth[$digit] ~~ /b/;
+
+ @matrix[4][0] = "|" if @truth[$digit] ~~ /e/;
+ @matrix[5][0] = "|" if @truth[$digit] ~~ /e/;
+
+ @matrix[4][6] = "|" if @truth[$digit] ~~ /c/;
+ @matrix[5][6] = "|" if @truth[$digit] ~~ /c/;
+
+ (^7).map({ ": " ~ @matrix[$_].join })>>.say if $verbose;
+
+ (^7).map({ @result[$_].push: @matrix[$_].join });
+}
+
+(^7).map({ @result[$_].join(" ") })>>.say;
diff --git a/challenge-200/arne-sommer/raku/ss200 b/challenge-200/arne-sommer/raku/ss200
new file mode 100755
index 0000000000..e87e70a1e2
--- /dev/null
+++ b/challenge-200/arne-sommer/raku/ss200
@@ -0,0 +1,39 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (UInt $int = 200, :v(:$verbose));
+
+my @truth = qw<abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg>;
+
+my @result;
+
+for $int.comb -> $digit
+{
+ say ":Digit: $digit -> @truth[$digit]" if $verbose;
+
+ my @matrix;
+
+ # (^7).map({ @matrix[$_] = (" " xx 7).Array; });
+ (^7).map({ @matrix[$_] = " ".comb.Array; });
+
+ @matrix[0] = ("-" xx 7).Array if @truth[$digit] ~~ /a/;
+ @matrix[3] = ("-" xx 7).Array if @truth[$digit] ~~ /g/;
+ @matrix[6] = ("-" xx 7).Array if @truth[$digit] ~~ /d/;
+
+ @matrix[1][0] = "|" if @truth[$digit] ~~ /f/;
+ @matrix[2][0] = "|" if @truth[$digit] ~~ /f/;
+
+ @matrix[1][6] = "|" if @truth[$digit] ~~ /b/;
+ @matrix[2][6] = "|" if @truth[$digit] ~~ /b/;
+
+ @matrix[4][0] = "|" if @truth[$digit] ~~ /e/;
+ @matrix[5][0] = "|" if @truth[$digit] ~~ /e/;
+
+ @matrix[4][6] = "|" if @truth[$digit] ~~ /c/;
+ @matrix[5][6] = "|" if @truth[$digit] ~~ /c/;
+
+ (^7).map({ ": " ~ @matrix[$_].join })>>.say if $verbose;
+
+ (^7).map({ @result[$_].push: @matrix[$_].join });
+}
+
+(^7).map({ @result[$_].join(" ") })>>.say;
diff --git a/challenge-200/arne-sommer/raku/ss200-minus b/challenge-200/arne-sommer/raku/ss200-minus
new file mode 100755
index 0000000000..ec2022ec1d
--- /dev/null
+++ b/challenge-200/arne-sommer/raku/ss200-minus
@@ -0,0 +1,45 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (UInt $int = 200, :v(:$verbose), :n(:$negative));
+
+my %truth = ( 0 => 'abcdef',
+ 1 => 'bc', 2 => 'abdeg', 3 => 'abcdg',
+ 4 => 'bcfg', 5 => 'acdfg', 6 => 'acdefg',
+ 7 => 'abc', 8 => 'abcdefg', 9 => 'abcfg',
+ '-' => 'g');
+
+my @result;
+
+for $negative ?? "-$int".comb !! $int.comb -> $digit
+{
+ die "Illegal input $digit" unless %truth{$digit};
+
+ say ":Digit: $digit -> %truth{$digit}" if $verbose;
+
+ my @matrix;
+
+ # (^7).map({ @matrix[$_] = (" " xx 7).Array; });
+ (^7).map({ @matrix[$_] = " ".comb.Array; });
+
+ @matrix[0] = ("-" xx 7).Array if %truth{$digit} ~~ /a/;
+ @matrix[3] = ("-" xx 7).Array if %truth{$digit} ~~ /g/;
+ @matrix[6] = ("-" xx 7).Array if %truth{$digit} ~~ /d/;
+
+ @matrix[1][0] = "|" if %truth{$digit} ~~ /f/;
+ @matrix[2][0] = "|" if %truth{$digit} ~~ /f/;
+
+ @matrix[1][6] = "|" if %truth{$digit} ~~ /b/;
+ @matrix[2][6] = "|" if %truth{$digit} ~~ /b/;
+
+ @matrix[4][0] = "|" if %truth{$digit} ~~ /e/;
+ @matrix[5][0] = "|" if %truth{$digit} ~~ /e/;
+
+ @matrix[4][6] = "|" if %truth{$digit} ~~ /c/;
+ @matrix[5][6] = "|" if %truth{$digit} ~~ /c/;
+
+ (^7).map({ ": " ~ @matrix[$_].join })>>.say if $verbose;
+
+ (^7).map({ @result[$_].push: @matrix[$_].join });
+}
+
+(^7).map({ @result[$_].join(" ") })>>.say;