From 00131a6afd8cc12e82f58cd49aa705a0b3d1a440 Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Mon, 29 Apr 2019 02:39:49 +0000 Subject: Add Perl 5 week 6 problem 1 --- challenge-006/joelle-maslak/perl5/ch-1.pl | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 challenge-006/joelle-maslak/perl5/ch-1.pl 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 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 ) ); + -- cgit