22
2
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!
Is it necessary to use
-
or are we allowed to use a different symbol? – miles – 2017-07-26T05:57:42.703@miles Will a different symbol save you bytes? – Adám – 2017-07-26T06:41:32.997
I am thinking of using infinity
_
so that I might remain operating on numeric arrays in J. – miles – 2017-07-26T06:45:05.980@miles Ah, yeah, why don't you go ahead and do that, but make a not about it, and if you can be bothered, write the (I assume much longer) boxed solution with
'-'
. You might also be able to stringify everything before inserting dashes, no? – Adám – 2017-07-26T07:03:32.973Is the following valid?
[3,5,-8,10,-12,14,16,-22,24]
(this seems to be the format that makes the most sense in terms of types) – Leaky Nun – 2017-07-26T09:02:38.980@LeakyNun Uh, are those negative numbers? If so, no. Not because the format is bad per se, but because I should have permitted it from the outset so others could do it to. However, can't you just stringify and replace
,-
with-
? – Adám – 2017-07-26T09:07:32.083