请帮助我使用一个函数来查找列表中的连续序列。
它适用于以下列表
q) list:100 4 200 1 3 2
q)st where (deltas st:asc list)=1
1 2 3 4
q)count st where (deltas st:asc list)=1
4
但是下面的示例未按预期返回结果。
q)list
10 15 1 2 3 4 5 11 12
q)st where (deltas st:asc list)=1
1 2 3 4 5 11 12 // expected result is 1 2 3 4 5
q)count st where (deltas st:asc list)=1
7
你可以尝试这样的事情:
1=deltas
将返回连续数字的布尔列表(如果存在)。然后我们可以1b
通过使用 s 将其分解来将 s 组合在一起0b
。我们可以通过将其转换为string
then 使用vs
来分解列表来做到这一点。最后,我们可以得到一count
组each
连续的数字并得到max
。与莫里斯的想法类似,但我们可以直接跳到最长的序列,而不必操作列表。