diff options
| -rw-r--r-- | challenge-006/arpad-toth/perl5/ch-1.sh | 6 |
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 :-) |
