Hw05 - CS61A of UCB(2021-Fall)
Q1: Generate Permutations
Given a sequence of unique elements, a permutation of the sequence is a list containing the elements of the sequence in some arbitrary order. For example,
[2, 1, 3]
,[1, 3, 2]
, and[3, 2, 1]
are some of the permutations of the sequence[1, 2, 3]
.Implement
gen_perms
, a generator function that takes in a sequenceseq
and returns a generator that yields all permutations ofseq
. For this question, assume thatseq
will not be empty.