Python Forum
Creating permutations of N size with no same elements next to one another (recursion)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating permutations of N size with no same elements next to one another (recursion)
#1
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!
Reply
#2
see: https://stackoverflow.com/a/70394153
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,098 May-17-2022, 11:38 AM
Last Post: Larz60+
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,579 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  What happens to a <itertools.permutations object at 0x7fe3cc66af68> after it is read? Pedroski55 3 2,378 Nov-29-2020, 08:35 AM
Last Post: DeaD_EyE
  Permutations mikke3141 2 20,236 Dec-23-2019, 06:09 PM
Last Post: mikke3141
  size of set vs size of dict zweb 0 2,134 Oct-11-2019, 01:32 AM
Last Post: zweb
  More Efficent Way of Generating Permutations/ w Rep ClassicalSoul 2 2,683 Aug-22-2019, 05:22 AM
Last Post: perfringo
  permutations calculation with a while instruction kwak86 2 2,263 Sep-10-2018, 02:09 PM
Last Post: kwak86
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,469 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb
  How to find the number of permutations of a list of lists? JoeB 5 5,326 Nov-18-2017, 06:31 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020