鉴于您提供的一小部分测试数据,我想出了这个:
def list = [[['o', 'g'], ['g', 'o']], [['o', 'g', 'o', 'd']], [['o', 'd']], [['t', 's', 'n', 'e', 'e', 'e', 'n', 'c', 's']], [['t', 's', 'n', 'e', 'e']], [['e', 'n', 'c', 's']]]
// For every combination of the lists
def result = list.combinations().collect { combination ->
// Join them into strings
combination*.join().with { stringcombo ->
// Then find every string in the list
stringcombo.findAll { word ->
// Which is not a substring of another string in the list
(stringcombo - word).every { it.indexOf( word ) == -1 }
}
}.permutations()*.join() // Then get every String permutation of these remaining strings
}.flatten().unique() // and get them into a single unique list
// And print them out
result.each {
println it
}
打印出来:
ogodtsneeencs
tsneeencsogod
没有更多数据,很难判断它是否正确,但这对您来说可能是一个很好的起点
编辑
更新以返回有效令牌的所有排列