From afb9cb7a63ec18805ffeeb3c713277456ca63f0b Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Mon, 29 Apr 2019 02:32:28 +0000 Subject: Add Perl6 for Week 6 Problem 1 --- challenge-006/joelle-maslak/perl6/ch-1.p6 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 challenge-006/joelle-maslak/perl6/ch-1.p6 diff --git a/challenge-006/joelle-maslak/perl6/ch-1.p6 b/challenge-006/joelle-maslak/perl6/ch-1.p6 new file mode 100755 index 0000000000..0e8a3f9a23 --- /dev/null +++ b/challenge-006/joelle-maslak/perl6/ch-1.p6 @@ -0,0 +1,29 @@ +#!/usr/bin/env perl6 +use v6; + +# To call this application: +# +# perl6 ch-1.p6 +# +# Numbers should be space seperated. +# + +my Pair $run; +my @runs; + +for @*ARGS.sort( { $^a <=> $^b } ) -> Int() $num { + if ! defined $run { + $run = Pair.new($num, $num); + } else { + if $run.value == $num - 1 { + $run = Pair.new($run.key, $num); + } else { + @runs.append($run); + $run = Pair.new($num, $num); + } + } + $run.freeze; +} +@runs.append($run) if defined $run; + +say join(",", @runs.map( { (.key ≠ .value) ?? "{.key}-{.values}" !! .key } ) ); -- cgit