【发布时间】:2012-12-06 16:43:35
【问题描述】:
我有一个文件:test.txt,每一行都有一个句子。
Hello World
99 Bottles of Beer
Humpty Dumpty Sat on the wall
我希望生成一个输出,显示来自该文件的输入的所有组合(即 2n-1 个组合)。在上面的例子中,算法将溢出以下内容 - 每个组合都用管道分隔 (|)
Hello World
99 Bottles of Beer
Humpty Dumpty Sat on the wall
Hello World | 99 Bottles of Beer
Hello World | Humpty Dumpty Sat on the wall
99 Bottles of Beer | Humpty Dumpty Sat on the wall
Hello World | 99 Bottles of Beer | Humpty Dumpty Sat on the wall
理想情况下,我希望在 bash、python 或 perl 脚本中完成此操作,但我愿意接受建议。
【问题讨论】:
-
你有没有尝试过但失败了?如果是,那是什么?
-
不是 (2^n)-1 吗?没有字符串的输出不是有效的吗?
标签: python bash combinations