aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2019-04-29 02:39:49 +0000
committerJoelle Maslak <jmaslak@antelope.net>2019-04-29 02:39:49 +0000
commit00131a6afd8cc12e82f58cd49aa705a0b3d1a440 (patch)
tree4810423b1a9779ece9681d2df51a745bae606210
parent8e83b81ba029c9bc1d7fa8dcf4be1b6e6a4fd270 (diff)
downloadperlweeklychallenge-club-00131a6afd8cc12e82f58cd49aa705a0b3d1a440.tar.gz
perlweeklychallenge-club-00131a6afd8cc12e82f58cd49aa705a0b3d1a440.tar.bz2
perlweeklychallenge-club-00131a6afd8cc12e82f58cd49aa705a0b3d1a440.zip
Add Perl 5 week 6 problem 1
-rwxr-xr-xchallenge-006/joelle-maslak/perl5/ch-1.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-006/joelle-maslak/perl5/ch-1.pl b/challenge-006/joelle-maslak/perl5/ch-1.pl
new file mode 100755
index 0000000000..f01b07d0ce
--- /dev/null
+++ b/challenge-006/joelle-maslak/perl5/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+use v5.26;
+use strict;
+use warnings;
+
+# Turn on method signatures
+use feature 'signatures';
+no warnings 'experimental::signatures';
+
+use autodie;
+
+# To call this application:
+#
+# perl ch-1.pl <numbers>
+#
+# Numbers should be space seperated.
+#
+
+my $run;
+my @runs;
+
+for my $num ( sort( { $a <=> $b } @ARGV ) ) {
+ if ( !defined $run ) {
+ $run = [ $num, $num ];
+ } else {
+ if ( $run->[1] == $num - 1 ) {
+ $run->[1] = $num;
+ } else {
+ push @runs, $run;
+ $run = [ $num, $num ];
+ }
+ }
+}
+push @runs, $run if defined $run;
+
+say join( ",", map( { ( $_->[0] != $_->[1] ) ? join( '-', @$_ ) : $_->[0] } @runs ) );
+