6 kyu

Range Parser

528 of 554DeepSpace

Description:

In this Kata you are to implement a function that parses a string which is composed from tokens of the form 'n1-n2,n3,n4-n5:n6' where 'nX' is a positive integer. Each token represent a different range:

'n1-n2' represents the range n1 to n2 (inclusive in both ends). 'n3' represents the single integer n3. 'n4-n5:n6' represents the range n4 to n5 (inclusive in both ends) but only includes every other n6 integer.

Notes:

  1. The input string doesn't not have to include all the token types.
  2. All integers are assumed to be positive.
  3. Tokens may be separated by ',', ', ' or ,.

Some examples:

'1-10,14, 20-25:2' -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 20, 22, 24]

'5-10' -> [5, 6, 7, 8, 9, 10]

'2' -> [2]

The output should be a list of integers.

Algorithms
Parsing
Strings
Fundamentals

Stats:

CreatedSep 9, 2016
PublishedSep 9, 2016
Warriors Trained949
Total Skips21
Total Code Submissions1925
Total Times Completed554
Python Completions528
Clojure Completions29
Total Stars35
% of votes with a positive feedback rating94% of 157
Total "Very Satisfied" Votes139
Total "Somewhat Satisfied" Votes16
Total "Not Satisfied" Votes2
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • DeepSpace Avatar
  • suic Avatar
  • lilsweetcaligula Avatar
  • mauro-1 Avatar
Ad