gpt4 book ai didi

wolfram-mathematica - Mathematica,字母表生成

转载 作者:行者123 更新时间:2023-12-04 16:24:51 25 4
gpt4 key购买 nike

如果我有一个字母表,假设 sigma = {1,2,3,4,a,b,c,d,e,f,g} 并且想要生成所有长度为 n 的单词,有没有办法做到这一点?

我可以做 Flatten[Outer[Function[{x, y}, {x, y}], sigma, sigma], 1]为 wordlength=2 做这件事,但它不会普遍化为更多的字母。
并且排列不起作用,因为它不包括 double 。Permutations[sigma, {2}]例如,不给出 {a,a}。

有没有一种简单的方法可以做到这一点,或者我必须为它编写一个函数?

这对于 n=2 是正确的(但我想要任意 n):

{{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, a}, {1, b}, {1, c}, {1, d}, {1, 
e}, {1, f}, {1, g}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, a}, {2,
b}, {2, c}, {2, d}, {2, e}, {2, f}, {2, g}, {3, 1}, {3, 2}, {3,
3}, {3, 4}, {3, a}, {3, b}, {3, c}, {3, d}, {3, e}, {3, f}, {3,
g}, {4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, a}, {4, b}, {4, c}, {4,
d}, {4, e}, {4, f}, {4, g}, {a, 1}, {a, 2}, {a, 3}, {a, 4}, {a,
a}, {a, b}, {a, c}, {a, d}, {a, e}, {a, f}, {a, g}, {b, 1}, {b,
2}, {b, 3}, {b, 4}, {b, a}, {b, b}, {b, c}, {b, d}, {b, e}, {b,
f}, {b, g}, {c, 1}, {c, 2}, {c, 3}, {c, 4}, {c, a}, {c, b}, {c,
c}, {c, d}, {c, e}, {c, f}, {c, g}, {d, 1}, {d, 2}, {d, 3}, {d,
4}, {d, a}, {d, b}, {d, c}, {d, d}, {d, e}, {d, f}, {d, g}, {e,
1}, {e, 2}, {e, 3}, {e, 4}, {e, a}, {e, b}, {e, c}, {e, d}, {e,
e}, {e, f}, {e, g}, {f, 1}, {f, 2}, {f, 3}, {f, 4}, {f, a}, {f,
b}, {f, c}, {f, d}, {f, e}, {f, f}, {f, g}, {g, 1}, {g, 2}, {g,
3}, {g, 4}, {g, a}, {g, b}, {g, c}, {g, d}, {g, e}, {g, f}, {g, g}}

最佳答案

关于wolfram-mathematica - Mathematica,字母表生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8390017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com