aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-05-03 17:09:58 +0100
committerGitHub <noreply@github.com>2019-05-03 17:09:58 +0100
commit4eb02327d38a1f1b09e245ca82ab21c38955ece5 (patch)
tree3b5aa0249965880cedd4c119cd05e1db4fa3111c
parent32ab749b5a997c7791867f6e7e1c4a5f6fdab8d1 (diff)
parent709d184f12ce09cbe3a30b64fc93f901373f43fc (diff)
downloadperlweeklychallenge-club-4eb02327d38a1f1b09e245ca82ab21c38955ece5.tar.gz
perlweeklychallenge-club-4eb02327d38a1f1b09e245ca82ab21c38955ece5.tar.bz2
perlweeklychallenge-club-4eb02327d38a1f1b09e245ca82ab21c38955ece5.zip
Merge pull request #116 from atothrp/new-branch
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 :-)