Jul-26-2018, 05:38 PM
(This post was last modified: Jul-26-2018, 06:06 PM by jarrod0987.)
(Jul-26-2018, 05:18 PM)ichabod801 Wrote: Permutations can be done with recursion:
def permutations(sequence, start = []): if not sequence: return [start] else: perms = [] for item in sequence: new_sequence = sequence[:] new_sequence.remove(item) perms.extend(permutations(new_sequence, start + [item])) return permsYou just need to add code blocking certain combinations when you recurse.
Just got done looking up search tree's but they are Binary and what I am doing is not. It also requires understanding of linked lists which I did not, so I looked those up. That required understanding of classes which I do not have a super strong grasp on but I have been working on that this afternoon. It seems like a lot of stuff to learn just to do something simple. This answer above, about using recursion and limiting it, that sounds much more like what I want to do. I don't really know how to write it. Could you make me a short example to study? Say to generate a list of permutations of 'ABC' but anything with BC (in that order) is not allowed and not added to the list?
If that takes too long, can you point me to a article that talks about how to write something like this?