【发布时间】:2010-08-11 10:25:59
【问题描述】:
给定一个字符串数组
["the" "cat" "sat" "on" "the" "mat"]
我希望从任何起始位置按顺序获取所有项目组合,例如
["the"]
["the" "cat"]
["the" "cat" "sat"]
...
["cat" "sat" "on" "the" "mat"]
["sat" "on" "the" "mat"]
["on" "the" "mat"]
...
["sat" "on"]
["sat" "on" "the"]
不允许与原始序列或缺少元素的组合,例如
["sat" "mat"] # missing "on"
["the" "on"] # reverse order
我还想知道这个操作是否有特定的名称,或者是否有更简洁的描述方式。
谢谢。
【问题讨论】:
标签: ruby arrays sequence combinations