Python Forum
Creating permutations of N size with no same elements next to one another (recursion) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Creating permutations of N size with no same elements next to one another (recursion) (/thread-35817.html)



Creating permutations of N size with no same elements next to one another (recursion) - melmoman - Dec-18-2021

Hello everyone! I am studying python from a Romanian book, and I have been trying some exercises on recursion.
I am quite struggling with this one: I am supposed to find all permutations of size K with recursion, without there being identical elements next to one another.
So, given a list [a,b,c,d] and K=3:
(a,b,c)
(a,b,d)
would be valid permutations.
The exercise asks precisely to append the permutations to a list (so generators are out of the question) and return it.
Any help would be appreciated.
Thanks in advance!


RE: Creating permutations of N size with no same elements next to one another (recursion) - Larz60+ - Dec-18-2021

see: https://stackoverflow.com/a/70394153