17
2
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.
Related challenge. – AdmBorkBork – 2018-06-05T13:45:17.867
@LuisfelipeDejesusMunoz Ah, I hadn't read natural in the challenge, sorry. Another question then: do natural numbers include 0? They usually don't – Luis Mendo – 2018-06-05T13:52:41.820
7
I've seen a few challenges you've posted recently with a lot of clarifying comments, and a couple closed as "unclear", and subsequently re-opened after you've made the appropriate edits. Have you considered posting these in the sandbox for a few days/a week? I've enjoyed your challenges since they're quite approachable, but all challenges, no matter how simple or by whom they're posted, can use refinement.
– Giuseppe – 2018-06-05T14:13:11.1102@Giuseppe Thanks for your suggestions. I have posted some other challenges in the sand box (usually if i don't get the right way to create a challenge with it i delete it). For these challenges I thought they were clear enough and that's why I posted immediately but I will start posting them in the sandbox first. Thanks – Luis felipe De jesus Munoz – 2018-06-05T14:15:57.883
May I output negative deltas? Like [-1, -1, -2] – Dead Possum – 2018-06-05T15:22:48.130
2@LuisMendo Heretic! 0 is a natural number! Billy Joel even had a whole album dedicated to the Peano Man! – ngm – 2018-06-05T15:46:56.983
@ngm I had it coming... the Billy-Joel-meets-number-theory reference actually made me giggle :-D – Luis Mendo – 2018-06-05T16:05:58.887
1
@AdmBorkBork, this is more related by virtue of dealing with arbitrary-length operation lists.
– Peter Taylor – 2018-06-06T06:29:26.003