I would like to generate all the permutations in the list, but I would like to filter out some of the permutations before they are added to the stack or saved anywhere.
I will filter out permutations based on some ad hoc custom rules.
In other words, I would like to generate a list of permutations of a large list (50-300 elements), but I would like to throw out most of the generated permutations directly during the process (I know that the total number of permutations is N! ).
I tried Ruby with my Array.permutation.to_a , but it looks like it supports a full stack at runtime, so I quickly ran out of memory (8 GB).
I also tried this Erlang solution, but it looks like it is similar to the previous Ruby.
Are there any individual solutions to this problem?
PS I read this and this , but unfortunately I do not know C / C ++.
source share