如何检测是否存在重复模式 [英] How to detect if a repeating pattern exists
问题描述
我的问题不是特定于语言的...我可能会用C#或Python来实现,除非语言的特定功能可以帮助我获得所需的内容.
My question isn't language specific... I would probably implement this in C# or Python unless there is a specific feature of a language that helps me get what I am looking for.
有人知道的某种算法可以帮助我确定数字列表是否包含重复模式吗?
Is there some sort of algorithm that anyone knows of that can help me determine if a list of numbers contains a repeating pattern?
假设我有几个数字列表...
Let's say I have a several lists of numbers...
[12, 4, 5, 7, 1, 2]
[1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 1, 1, 1, 1, 1]
[ 1, 2, 4, 12, 13, 1, 2, 4, 12, 13]
我需要检测每个列表中是否存在重复模式...例如,列表1返回false,但是列表2、3和4返回true.
I need to detect if there is a repeating pattern in each list... For example, list 1 returns false, but and lists 2, 3, and 4 return true.
我在想也许要对列表中出现的每个值进行计数,如果val 1 == val 2 == val n ...那就可以了.还有更好的主意吗?
I was thinking maybe taking a count of each value that appears in the list and if val 1 == val 2 == val n... then that would do it. Any better ideas?
推荐答案
您要查看信号的自相关.自相关基本上是将信号与其自身进行卷积.当您反复将一个信号滑过另一个信号,并且有重复的模式时,输出将产生强烈的共振.
You want to look at the autocorrelation of the signal. Autocorrelation basically does a convolution of the signal with itself. When a you iteratively slide one signal across another, and there is a repeating pattern, the output will resonate strongly.
这篇关于如何检测是否存在重复模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!