+ 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
115 Réponses
+ 74
Can you explain your challenge again? I read it 7 times and couldn't understand it at all
+ 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 )
+ 29
Is this correct?
https://code.sololearn.com/cpLoW2t98C33/?ref=app
+ 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
+ 11
heres mine...
check it out
https://code.sololearn.com/cR5W3Apl54iY/?ref=app
+ 10
https://code.sololearn.com/cc7xQx2R90mr/?ref=app
+ 10
Here is a short version, just to use elegantly python's possibilities
https://code.sololearn.com/ciH9qbyCE6bA
+ 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)
+ 8
for
-3,-2,-1
it shud be
-3--1
i mean the seperation dash..
😊☺😀
+ 6
https://code.sololearn.com/c1TO34Y5k6BY/?ref=app
+ 5
Ok now I get it but still dislike the syntax you used
+ 5
Your code is nice, more simple than mine.
I am your 1K follower Kantan LOL
+ 5
https://code.sololearn.com/cBrxm7bkDhXD/?ref=app
+ 5
Here's my try :
https://code.sololearn.com/cmr1XRN2db8M/?ref=app
+ 5
It isn't the shortest possible, I believe, but at least readable
https://code.sololearn.com/c8MF0pQ721l6/?ref=app
+ 5
Here is my try as web...
https://code.sololearn.com/WnXK2sxw2cum/?ref=app
+ 4
https://code.sololearn.com/cDvBhCUDJg0t/?ref=app