+ 103

Challenge: Range Extraction.

Write a program that takes a list of integers in increasing order and returns a correctly formatted string in the range format. Example: Input: [-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20] Output "-6,-3-1,3-5,7-11,14,15,17-20" Example 2: Input: [-5,-4,0,5,6,7,9,10] output: "-5,-4,0,5-7,9,10" Example 3: Input: [1,2,3,5,6,8,9,10,11] Output: "1-3,5,6,8-11" Note: a range spans at least 3 numbers. e.g. 1,2,3: 1-3 and 5,6: 5,6 and 8,9,10,11: 8-11 Have fun! Here, the reference: https://www.rosettacode.org/wiki/Range_extraction and here the kata: https://www.codewars.com/kata/51ba717bb08c1cd60f00002f

2nd Sep 2017, 3:33 PM
ysraelcon
ysraelcon - avatar
115 Réponses
+ 74
Can you explain your challenge again? I read it 7 times and couldn't understand it at all
2nd Sep 2017, 2:05 AM
Dapper Mink
Dapper Mink - avatar
2nd Sep 2017, 1:17 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 45
For those Who don't understand the challenge basicly if you have a range of numbers like 0,1,2,3,5,6,7 the output Will be 0-3,5-7 indicating the number in range beetween 0 and 3 in increasing order and then from 5-7 beacuse they have both in beetween numbers that are consequential. ( Sorry for the bad english )
4th Sep 2017, 4:47 PM
Automation
Automation - avatar
2nd Sep 2017, 1:52 AM
Rick
Rick - avatar
+ 21
for those who might not understand: take a list of integers which increase in order and find 3+ numbers which follow each other directly, example: 1,2,3 or 6,7,8 or 17,18,19, and make them into the format of 1-3, 6-8, 17-19, and include the other numbers. OK so to clarify, a list - [-6,-5,-2,0,1,2,3,6,7,9,10,11] when you change it to the required format: "-6,-5,-2,0-3,6,7,9-11" So we are just grouping 3 or more consecutive numbers in a list. If I've made a mistake feel free to correct me in the comments
4th Sep 2017, 5:26 PM
Albert Kyei
Albert Kyei - avatar
2nd Sep 2017, 12:27 PM
sayan chandra
sayan chandra - avatar
+ 10
https://code.sololearn.com/cc7xQx2R90mr/?ref=app
2nd Sep 2017, 11:53 AM
hamletmun
hamletmun - avatar
+ 10
Here is a short version, just to use elegantly python's possibilities https://code.sololearn.com/ciH9qbyCE6bA
3rd Sep 2017, 11:10 AM
VcC
VcC - avatar
+ 9
Extremely badly done but I don't care, there you go: https://code.sololearn.com/WmJhk7XEf30K/?ref=app (link's not working anymore cuz code removed)
2nd Sep 2017, 2:50 AM
Dapper Mink
Dapper Mink - avatar
+ 8
for -3,-2,-1 it shud be -3--1 i mean the seperation dash.. 😊☺😀
2nd Sep 2017, 2:15 AM
sayan chandra
sayan chandra - avatar
+ 6
https://code.sololearn.com/c1TO34Y5k6BY/?ref=app
4th Sep 2017, 10:31 PM
Gami
Gami - avatar
+ 5
Ok now I get it but still dislike the syntax you used
2nd Sep 2017, 2:16 AM
Dapper Mink
Dapper Mink - avatar
+ 5
Your code is nice, more simple than mine. I am your 1K follower Kantan LOL
2nd Sep 2017, 4:24 AM
Rick
Rick - avatar
2nd Sep 2017, 5:49 PM
Izi Lior Katie
Izi Lior Katie - avatar
+ 5
https://code.sololearn.com/cBrxm7bkDhXD/?ref=app
4th Sep 2017, 7:19 PM
Mohammad
Mohammad - avatar
4th Sep 2017, 8:40 PM
LukArToDo
LukArToDo - avatar
+ 5
It isn't the shortest possible, I believe, but at least readable https://code.sololearn.com/c8MF0pQ721l6/?ref=app
5th Sep 2017, 12:09 AM
Agravein
Agravein - avatar
8th Sep 2017, 11:53 AM
LukArToDo
LukArToDo - avatar
+ 4
https://code.sololearn.com/cDvBhCUDJg0t/?ref=app
4th Sep 2017, 3:25 PM
ALADI KENNETH
ALADI KENNETH - avatar