未知sou的检测周期

2024-05-18 13:57:47 发布

您现在位置:Python中文网/ 问答频道 /正文

如何检测无限序列中的重复数字?我尝试过Floyd&;Brent检测算法,但一无所获。。。 我有一个生成从0到9(包括0到9)的数字的生成器,我必须识别其中的一个句点。

示例测试用例:

import itertools

# of course this is a fake one just to offer an example
def source():
    return itertools.cycle((1, 0, 1, 4, 8, 2, 1, 3, 3, 1))

>>> gen = source()
>>> period(gen)
(1, 0, 1, 4, 8, 2, 1, 3, 3, 1)

Tags: ofimport算法示例source测试用例序列数字

热门问题