Challenge
Given a sequence of numbers, create a function which returns the sequence steps.
- Assume a sequence will be
N >= 3
- Sequence will repeat it steps at least once
- Sequence will only contain natural numbers
- Your function or program should return the shortest possible sequence of steps
Example:
Input: [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17]
Output: [1, 1, 2]
Explanation: The initial sequence goes from 1 => 2 (1 step), 2 => 3 (1 step), 3 => 5 (2 steps)
. Then it repeats. The output then is [1 step, 1 step, 2 steps] => [1, 1, 2]
Another example:
Input: [2, 5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20]
Output: [3, 1, 1, 1]
[2, 5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20]
\ /\ /\ /\ /
3 1 1 1 Then it repeats...
Test Cases
Input: [1, 4, 8, 9, 10, 13, 17, 18, 19, 22, 26, 27, 28] => Output: [3,4,1,1]
Input: [6, 11, 13, 18, 20, 25, 27, 32, 34, 39, 41] => Output: [5,2]
Input: [2, 6, 10, 13, 17, 21, 25, 28, 32, 36, 40, 43, 47] => Output: [4,4,3,4]
Input: [5, 6, 7] => Output: [1]
Clarifications
- The input length - 1 is divisible by the output length
- Assume sequence will always going to be increasing
This is code-golf, so the shortest answer in bytes win.