aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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(',');