In this challenge you will be given a list of positive integers which represents some range of integers which has been truncated for display. Your job is to find the missing bits and insert ellipses to show that that part has been truncated.
The input will always be strictly ascending and if two consecutive values differ by more than 1 then we know some data has been removed in between them.
For example if the input is:
20 differ by more than 1 we insert an ellipsis between them:
However if the consecutive values differ by exactly two, then we just reinsert the missing value (their mean), since an ellipsis doesn't actually save any space when it's just covering 1 value.
So for example if the input is:
5 differ by more than 1 so data has been removed between them, but they differ by 2 so we just insert the missing
Additionally if the first value is greater than
1 we know that something has been truncated off the front. So we add an ellipsis, or if the first value is
1 as the first value. We can't know that something has been truncated off the end so we never add anything there.
Given a list of positive strictly-ascending integers as input output the list with the proper insertions. You can represent ellipses in the output as any constant value other than a positive integer. For the convenience of strongly typed programming, you may also output a list of optional values with the null value representing ellipses.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
[1,2,3,4,20,21,22] -> [1,2,3,4,...,20,21,22] [1,2,3,5,6] -> [1,2,3,4,5,6] [2,3,4,9] -> [1,2,3,4,...,9] [3,5,7,8,10] -> [...,3,4,5,6,7,8,9,10] [1,20,23] -> [1,...,20,...,23]