diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-29 03:41:30 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-29 03:41:30 +0100 |
| commit | 763c43607d84523cd559db8269f5948b31cd4424 (patch) | |
| tree | 0b01b8dbc0e0ea4b085f2243483906268b5763ec | |
| parent | 95cbdcd52fed245f8e25b333af8b33470d4d48c0 (diff) | |
| parent | 8e83b81ba029c9bc1d7fa8dcf4be1b6e6a4fd270 (diff) | |
| download | perlweeklychallenge-club-763c43607d84523cd559db8269f5948b31cd4424.tar.gz perlweeklychallenge-club-763c43607d84523cd559db8269f5948b31cd4424.tar.bz2 perlweeklychallenge-club-763c43607d84523cd559db8269f5948b31cd4424.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
| -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 } ) ); |
