level 7
combinations_with_replacement(iterable, r)
返回iterable中所有长度为r的子序列,返回的子序列中的项按输入iterable中的顺序排序,带重复
combinations_with_replacement([1, 2, 3], 2)
输出:
(1, 1)(1, 2)(1, 3)(2, 2)(2, 3)(3, 3)
2017年12月28日 15点12分
1
吧务
level 12
然后提供一个简单点的写法。虽然速度比上面链接里的那个差一点
combWithRep[list_List, k_Integer] :=
list[[# - Range[0, k - 1]]] & /@ Subsets[Range[Length[list] + k - 1], {k}]
2017年12月29日 01点12分
3