Home How to get all possible combinations of a list’s elements?
Reply: 0

How to get all possible combinations of a list’s elements?

user635
1#
user635 Published in July 23, 2018, 9:59 am

I have a list with 15 numbers in, and I need to write some code that produces all 32,768 combinations of those numbers.

I've found some code (by Googling) that apparently does what I'm looking for, but I found the code fairly opaque and am wary of using it. Plus I have a feeling there must be a more elegant solution.

The only thing that occurs to me would be to just loop through the decimal integers 1–32768 and convert those to binary, and use the binary representation as a filter to pick out the appropriate numbers.

Does anyone know of a better way? Using map(), maybe?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.539429 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO