M
Max Williams
can anyone provide an elegant implementation for this method?
#gives all distinct combinations of numbers up to n, with maximum size
max_size
def permutations(n,max_size)
so, eg,
permutations(4,2)
=> [[1],[2],[3],[4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
permutations(4,3)
=> above + [[1,2,3],[1,2,4],[2,3,4]]
i'm guessing something recursive is the key but i can't quite work out
the best way.
thanks
max
#gives all distinct combinations of numbers up to n, with maximum size
max_size
def permutations(n,max_size)
so, eg,
permutations(4,2)
=> [[1],[2],[3],[4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
permutations(4,3)
=> above + [[1,2,3],[1,2,4],[2,3,4]]
i'm guessing something recursive is the key but i can't quite work out
the best way.
thanks
max