aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tim.dolores@gmail.com>2019-04-30 22:21:39 -0400
committerTim Smith <tim.dolores@gmail.com>2019-04-30 23:55:36 -0400
commitdb975fdc5292458acb5277082fb21c9faeeedeb5 (patch)
tree16aef55b445ede838b5bd0ddf8d1d5aeb8bf70f2
parent2f5ee8d01e0212d9c8e587014b0df2710e0b0ef1 (diff)
downloadperlweeklychallenge-club-db975fdc5292458acb5277082fb21c9faeeedeb5.tar.gz
perlweeklychallenge-club-db975fdc5292458acb5277082fb21c9faeeedeb5.tar.bz2
perlweeklychallenge-club-db975fdc5292458acb5277082fb21c9faeeedeb5.zip
Add tim-smith/perl6/ch-1.p6
-rwxr-xr-xchallenge-006/tim-smith/perl6/ch-1.p621
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-006/tim-smith/perl6/ch-1.p6 b/challenge-006/tim-smith/perl6/ch-1.p6
new file mode 100755
index 0000000000..506c8802e9
--- /dev/null
+++ b/challenge-006/tim-smith/perl6/ch-1.p6
@@ -0,0 +1,21 @@
+#! /usr/bin/env perl6
+
+# Comb all args for numbers, then flatten them into a single list of
+# increasing integers
+my @vals = @*ARGSĀ».comb(/\d+/).Seq.flatĀ».Int.sort.unique
+ or die "Usage: {$?FILE.IO.basename} 1 2,3 4/5/6 '7 8 9'";
+
+my @groups;
+
+for @vals -> $n {
+ # Add a new group unless $n belongs in the current group
+ unless @groups and @groups.tail[1] == $n - 1 {
+ @groups.push: [$n, Nil];
+ }
+
+ # Update the endpoint of the current group
+ @groups.tail[1] = $n;
+}
+
+# Display the groups
+put @groups.map(*.unique.join('-')).join(',');