Related: Tell me how many math problems I have to do!
Challenge
Given a strictly positive strictly ascending integer list L and an integer 3 ≤ N ≤ length of L, replace the middle integers of L's consecutive integer runs of length ≥ N with a single dash -
.
Rules
- Horizontal whitespace is irrelevant.
- You may optionally preserve the introducer, separator, and terminator characters of your language's default list format. See Format examples, below.
Data examples
All these examples use L = 3 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 24
.
N = 3
→ 3 5 - 8 10 - 12 14 16 - 22 24
N = 4
→ 3 5 - 8 10 11 12 14 16 - 22 24
N = 5
→ 3 5 6 7 8 10 11 12 14 16 - 22 24
N = 8
→ 3 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 24
Format examples
For the inputs
L = [3,5,6,7,8,10,11,12,14,16,17,18,19,20,21,22,24]
and N = 3
all the below lines are examples of valid responses, both as actual lists and as strings:
[3,5,"-",8,10,"-",12,14,16,"-",22,24]
[3,5,-,8,10,-,12,14,16,-,22,24]
[3,5-8,10-12,14,16-22,24]
3,5-8,10-12,14,16-22,24
The same applies with other list formats, like {1 2 3}
and (1; 2; 3)
etc. In doubt? Ask!
-
or are we allowed to use a different symbol? \$\endgroup\$_
so that I might remain operating on numeric arrays in J. \$\endgroup\$'-'
. You might also be able to stringify everything before inserting dashes, no? \$\endgroup\$