挑战
给定一个数字序列,创建一个返回序列步骤的函数。
- 假设一个序列将是
N >= 3
- 序列将至少重复一次该步骤
- 序列将仅包含自然数
- 您的函数或程序应返回最短的步骤顺序
例:
输入: [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17]
输出: [1, 1, 2]
说明:初始序列来自1 => 2 (1 step), 2 => 3 (1 step), 3 => 5 (2 steps)
。然后重复。输出是[1 step, 1 step, 2 steps] => [1, 1, 2]
另一个例子:
输入: [2, 5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20]
输出: [3, 1, 1, 1]
[2, 5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20]
\ /\ /\ /\ /
3 1 1 1 Then it repeats...
测试用例
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]
澄清说明
- 输入长度-1可被输出长度整除
- 假设顺序总是会增加
这是代码高尔夫球,因此最短的答案以字节为单位。