diff options
| -rwxr-xr-x | challenge-006/joelle-maslak/perl6/ch-1.p6 | 29 |
1 files changed, 29 insertions, 0 deletions
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> +# +# 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 } ) ); |
