Submit an Entry

To enter the challenge, you need to signup or login.

This Challenge's Best Entries [View All]

(View the Overall | Perl | PHP | Python | Ruby leaderboard.)

Rank User Size Language Score [?]
1st Aidy 50 Perl 10,000 (v12)
2nd dmo 50 Perl 10,000 (v17)
3rd Jasper 51 Perl 9,803 (v14)
4th o0lit3 52 Perl 9,615 (v33)
5th terjek 53 Perl 9,433 (v10)
6th kinaba 53 Perl 9,433 (v7)
7th ozy4dm 53 Perl 9,433 (v25)
8th kounoike 53 Perl 9,433 (v15)
9th flagitious 54 Perl 9,259 (v50)
10th robin 54 Perl 9,259 (v13)

See who is active in this challenge →

Home On The Range

(Challenge added 738 days ago.)

It's as simple as "1 2 3 5 6 8" => "1-3, 5-6, 8."

Discuss This Challenge →

The Problem

It's difficult to spot what's missing in a long list of numbers if they are just listed one after the other. You can make it easier by organising the numbers into ranges, and that's exactly what you're going to do here.

Your program will receive a set of space-separated numbers on stdin, and it will be expected to print a set of ranges on stdout formatted according to the following rules :

  • Numbers which appear sequentially in the input should be grouped with the first number and last number in the sequence separated by a hyphen.
  • Numbers which appear in the input on their own should not be collapsed into a range.
  • Ranges and single numbers in your output should be separated by a comma and a space (", "), and the list of ranges should end with a full-stop (".")

Examples

  • "1 2 3" => "1-3."
  • "1 2 3 5 7 8" => "1-3, 5, 7-8."
  • "1 3 4 5 7" => "1, 3-5, 7."

Other Information

  • Your program will be ran three times with increasingly more numbers.
  • There will be a maximum of 500 numbers given to your program, and the maximum value of an individual number will be 500.
  • The numbers will be given in ascending order.
  • The input to each of the three runs will be different each time you upload an entry.