aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoratothrp <atoth20@cogeco.ca>2019-05-02 17:59:35 -0400
committeratothrp <atoth20@cogeco.ca>2019-05-02 17:59:35 -0400
commit709d184f12ce09cbe3a30b64fc93f901373f43fc (patch)
tree3b5aa0249965880cedd4c119cd05e1db4fa3111c
parent32ab749b5a997c7791867f6e7e1c4a5f6fdab8d1 (diff)
downloadperlweeklychallenge-club-709d184f12ce09cbe3a30b64fc93f901373f43fc.tar.gz
perlweeklychallenge-club-709d184f12ce09cbe3a30b64fc93f901373f43fc.tar.bz2
perlweeklychallenge-club-709d184f12ce09cbe3a30b64fc93f901373f43fc.zip
challenge-006/arpad-toth/perl5/ch-1.sh
-rw-r--r--challenge-006/arpad-toth/perl5/ch-1.sh6
1 files changed, 6 insertions, 0 deletions
diff --git a/challenge-006/arpad-toth/perl5/ch-1.sh b/challenge-006/arpad-toth/perl5/ch-1.sh
new file mode 100644
index 0000000000..ba7a8c24c5
--- /dev/null
+++ b/challenge-006/arpad-toth/perl5/ch-1.sh
@@ -0,0 +1,6 @@
+#Create a script which takes a list of numbers from command line and print the same in the compact form.
+#For example, if you pass “1,2,3,4,9,10,14,15,16” then it should print the compact form like “1-4,9,10,14-16”.
+#one liner, runs fine in my rhel 7.6 terminal bash shell
+perl -e '@nu=split/,/,shift;$i=0;do{if($nu[$i]+1==$nu[$i+1] && $nu[$i]+2==$nu[$i+2] && $j==0){print "$nu[$i]-";$i++;$j=1}elsif($j==1 && $nu[$i]+1==$nu[$i+1]){$i++}else{print "$nu[$i],";$i++;$j=0}}while($i<=$#nu)' 1,2,3,4,9,10,14,15,16
+
+#happy coding :-)