两个序列之间的公共字符串

Common strings between two sequences

我有两个与同一主题相关的问题。我运行模拟了100个元素的16000个序列,没有重复,数字在1-4之间,例如:124232143214223142314...

进行这些模拟是为了了解随机生成的序列和预定义序列之间最长的共同序列是什么。还要求参与者这样做,以生成他们之前在不知不觉中学习的序列。

我想找到两个序列之间所有共同的三胞胎。 因此,如果我们有序列 A:12342134213421313242... 和序列 B:21342134123214。它必须计算所有共同的三胞胎 包括重复次数:213、134、342、213 等

尝试这样的事情:

import itertools

x = "12342134213421313242123"
y = "213421341232123"
m = ["1","2","3","4"]

#dict of triplet vs [no of repetitions in x, in y]
z={k: [x.count(k), y.count(k)] for k in ["".join(el) for el in [a+b+c for a in m for b in m for c in m if a!=b and b!=c and a!=c]]}
#total number of common triplets:
z_no = sum([x.count(k) if x.count(k)>0 and y.count(k)>0 else 0 for k in ["".join(el) for el in [a+b+c for a in m for b in m for c in m if a!=b and b!=c and a!=c]]])
#broken down by triplet
z_final = {k: v[0] for k,v in z.items() if v[0]>0 and v[1]>0}