2
\$\begingroup\$

Inspired by Using LaTeX to compact a list of numbers, this challenge is to output a compact list of numbers, given a range, as follows:

Input: 1,2, 3,4,5,8,11, 12,13
Output: 1-5, 8, 11-13

Input: 20,21,45,56,75, 76,77,78
Output: 20-21, 45, 56, 75-78

Input: 4,5
Output: 4-5

Input is always comma separated numbers, sometimes with spacing, and output should be in the format above -- note space after the commas. There is no upper limit to the length of the input string.

Winner: Smallest in terms of bytes

\$\endgroup\$
1
  • 4
    \$\begingroup\$ This is a nice first challenge :). Sadly, apart from sorting the array, it's the exact same challenge as this. \$\endgroup\$
    – Adnan
    Aug 25 '16 at 13:20

Browse other questions tagged or ask your own question.