我是一位有用的助手,可以为您翻译文本。
我正在寻找解决以下问题的算法:
我有一组数字。
我正在寻找解决以下问题的算法:
我有一组数字。
(e.g 100,74,104,76,29,79,98,33,201)
我希望将相邻(差值为x)的数字分组。
例如,当x=10时,应输出:
[(100,104,98) (74,76,79) (33,29) (201)]
很不幸,我不知道如何做到这一点。
编辑:我有很多初始想法。算法不必高效,只要能工作就可以。
其中一个是:
- A) Picking first number, comparing its size with all the other numbers
- B) If the condition is complied, saving it in another set and deleting it from the input set
- C) Select the next element that isn't deleted and Start at A (Proceed until input set is empty)
你认为怎么样?