Given an unsorted list of unique, positive integers, output the shortest list of the longest possible ranges of sequential integers.
INPUT
- An unsorted list of unique, positive integers
- e.g.
9 13 3 11 8 4 10 15
- e.g.
- Input can be taken from any one of the following:
stdin
- command-line arguments
- function arguments
OUTPUT
- An ordered list of ranges or individual values printed on one line to stdout or your language's closest similar output.
- If two or more sequential integers (sequential by value, not by location in the list) are present, they will be denoted as an inclusive range using -, e.g.
8-11
- All other integers are simply printed with no other notation
- A single space will delimit the output
- If two or more sequential integers (sequential by value, not by location in the list) are present, they will be denoted as an inclusive range using -, e.g.
- Numbers not present in the input should not be in the output, e.g.
3 5 6
cannot be shortened to3-6
because4
is not present
EXAMPLES
Successful:
IN> 9 13 3 11 8 4 10 15 6
OUT> 3-4 6 8-11 13 15
IN> 11 10 6 9 13 8 3 4 15
OUT> 3-4 6 8-11 13 15
IN> 5 8 3 2 6 4 7 1
OUT> 1-8
IN> 5 3 7 1 9
OUT> 1 3 5 7 9
Wrong:
IN> 9 13 3 11 8 4 10 15
OUT> 3-15
Range contains values not in the input
IN> 9 13 3 11 8 4 10 15
OUT> 3 4 8 9 10 11 13 15
All sequential values should be represented as a range
IN> 9 13 3 11 8 4 10 15
OUT> 3-4 8-9 10-11 13 15
Divided range, 8-9
and 10-11
should be 8-11
IN> 9 13 3 11 8 4 10 15
OUT> 8-9 13 10-11 3-4 15
Output not ordered correctly
RULES
- Standard loopholes are disallowed
- If your language has a function to do this it's not allowed
- You may write a full program, or a function
- trailing whitespace doesn't matter
SCORING
- Least bytes wins