Let's say we have a list of elements:
[{dog,1},{dog,2},{cat,1},{cat,2},{bird,1},{bird,2},...]
I would like to store all possible permutations of this list in the RAM.
Since the list can be pretty long (10 elements and more), it takes a lot of space to store it (factorial N).
For instance, if I have a list, which consumes about 70 bytes of space and has 12 elements, then I need 12! * 70 ~ 31 GB
. If I add just one more element to the list, then it could become unfeasible to store the permutations in the RAM.
Is there any more efficient representation to keep all the permutations in the memory than the following Erlang representation?
[{dog,1},{dog,2},{cat,1},{cat,2},{bird,1},{bird,2},...]
(I know that the atom dog
is stored only once in the atoms table, but since it is repeated in every permutation, it takes N memory).
Maybe these permutations could be stored in some kind of byte representation? (Sorry, I am a newbie in bytes and binaries).
After all, it is just the same elements, but rearranged in different ways.