aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnesom <arne@bbop.org>2022-12-25 23:54:04 +0100
committerarnesom <arne@bbop.org>2022-12-25 23:54:04 +0100
commit447112a26259b6344e23b928247fae8a2c36146c (patch)
treed0439fb872681025b4eb4abae9f1d3d1e4c1065c
parentdbf3892dcde85f90f1d809e9519e6e11643fc099 (diff)
downloadperlweeklychallenge-club-447112a26259b6344e23b928247fae8a2c36146c.tar.gz
perlweeklychallenge-club-447112a26259b6344e23b928247fae8a2c36146c.tar.bz2
perlweeklychallenge-club-447112a26259b6344e23b928247fae8a2c36146c.zip
Arne Sommer
-rw-r--r--challenge-196/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-196/arne-sommer/raku/ch-1.raku22
-rwxr-xr-xchallenge-196/arne-sommer/raku/ch-2.raku25
-rwxr-xr-xchallenge-196/arne-sommer/raku/pattern13222
-rwxr-xr-xchallenge-196/arne-sommer/raku/range-list25
5 files changed, 95 insertions, 0 deletions
diff --git a/challenge-196/arne-sommer/blog.txt b/challenge-196/arne-sommer/blog.txt
new file mode 100644
index 0000000000..79b9ee98cb
--- /dev/null
+++ b/challenge-196/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/132-lists.html
diff --git a/challenge-196/arne-sommer/raku/ch-1.raku b/challenge-196/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..1871d00202
--- /dev/null
+++ b/challenge-196/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,22 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@list where @list.elems > 0 && all(@list) ~~ /^<[1..9]><[0..9]>*$/);
+
+my $end = @list.elems - 1;
+
+for 0 .. $end - 2 -> $i
+{
+ for $i + 1 .. $end - 1 -> $j
+ {
+ for $j + 1 .. $end -> $k
+ {
+ if @list[$i] < @list[$k] < @list[$j]
+ {
+ say "(@list[$i], @list[$j], @list[$k])";
+ exit;
+ }
+ }
+ }
+}
+
+say "()";
diff --git a/challenge-196/arne-sommer/raku/ch-2.raku b/challenge-196/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..c226623d63
--- /dev/null
+++ b/challenge-196/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@array where @array.elems > 1 && all(@array) ~~ /^<[0..9]>+$/ && [<] @array);
+
+my @ranges;
+my $from = @array.shift.Int;
+my $to = $from;
+
+while @array
+{
+ my $next = @array.shift.Int;
+ if $next == $to + 1
+ {
+ $to = $next;
+ }
+ else
+ {
+ @ranges.push([$from, $to]) if $to > $from;
+ $from = $to = $next;
+ }
+}
+
+@ranges.push([$from, $to]) if $to > $from;
+
+say @ranges.raku;
diff --git a/challenge-196/arne-sommer/raku/pattern132 b/challenge-196/arne-sommer/raku/pattern132
new file mode 100755
index 0000000000..1871d00202
--- /dev/null
+++ b/challenge-196/arne-sommer/raku/pattern132
@@ -0,0 +1,22 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@list where @list.elems > 0 && all(@list) ~~ /^<[1..9]><[0..9]>*$/);
+
+my $end = @list.elems - 1;
+
+for 0 .. $end - 2 -> $i
+{
+ for $i + 1 .. $end - 1 -> $j
+ {
+ for $j + 1 .. $end -> $k
+ {
+ if @list[$i] < @list[$k] < @list[$j]
+ {
+ say "(@list[$i], @list[$j], @list[$k])";
+ exit;
+ }
+ }
+ }
+}
+
+say "()";
diff --git a/challenge-196/arne-sommer/raku/range-list b/challenge-196/arne-sommer/raku/range-list
new file mode 100755
index 0000000000..c226623d63
--- /dev/null
+++ b/challenge-196/arne-sommer/raku/range-list
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@array where @array.elems > 1 && all(@array) ~~ /^<[0..9]>+$/ && [<] @array);
+
+my @ranges;
+my $from = @array.shift.Int;
+my $to = $from;
+
+while @array
+{
+ my $next = @array.shift.Int;
+ if $next == $to + 1
+ {
+ $to = $next;
+ }
+ else
+ {
+ @ranges.push([$from, $to]) if $to > $from;
+ $from = $to = $next;
+ }
+}
+
+@ranges.push([$from, $to]) if $to > $from;
+
+say @ranges.raku;