2
我有一个数据结构,它看起来像这样:递归地解决置换
[
{:choices=>["Hello", "Hi"]},
" ",
{:choices=>["wor", {:choices=>["ld", "d"]}, "there"]},
", says ",
"your ",
{:choices=>["friend", "amigo"]}
]
在这种结构中,选择节点表示的一组可能值的和可以由。
我需要一个(可能是递归的)Ruby方法,它将输出所有可能输出的数组。即,在这个例子:
[
"Hello word, says your friend",
"Hello world, says your friend",
"Hello there, says your friend",
"Hi word, says your friend",
"Hi world, says your friend",
"Hi there, says your friend",
"Hello word, says your amigo",
"Hello world, says your amigo",
"Hello there, says your amigo",
"Hi word, says your amigo",
"Hi world, says your amigo",
"Hi there, says your amigo"
]
我希望这是递归的,但我一直在敲打它我的头一个小时,我想多了一双眼睛。我在这里错过了什么?
你的数据结构是错误的。 “wor”,'{:choices => [“ld”,“d”]}','“there”三个元素将被解释为替代,因此不会给出您想要的结果。 – sawa 2011-12-25 04:52:17