# Is there an elegant way to generate the permutations of all the members of a set?

**URL:** <https://discourse.processing.org/t/is-there-an-elegant-way-to-generate-the-permutations-of-all-the-members-of-a-set/31810>\
**Category:** Coding Questions\
**Created:** [August 20, 2021, 5:04pm UTC](https://discourse.processing.org/t/is-there-an-elegant-way-to-generate-the-permutations-of-all-the-members-of-a-set/31810 "2021-08-20T17:04:55Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [August 20, 2021, 7:44pm UTC](https://discourse.processing.org/t/is-there-an-elegant-way-to-generate-the-permutations-of-all-the-members-of-a-set/31810/8 "2021-08-20T19:44:59Z")

</div>

I was trying to work out the algorithm used in the Python approach mentioned by @jeremydouglass

I _think_ it is Heap’s algorithm so then I looked up Heap’s algorithm in Processing and found this: [Storing all index permutations with Heap's algorithm](https://discourse.processing.org/t/storing-all-index-permutations-with-heaps-algorithm/22326)

More follows.  
And here is the Steinhaus–Johnson–Trotter algorithm in JS [https://codepen.io/jbranchaud/pen/gbRGBp](https://codepen.io/jbranchaud/pen/gbRGBp)  
and in ALGOL 60 !!! [https://dl.acm.org/doi/10.1145/368637.368660](https://dl.acm.org/doi/10.1145/368637.368660)

---

_[View the full topic](https://discourse.processing.org/t/is-there-an-elegant-way-to-generate-the-permutations-of-all-the-members-of-a-set/31810)._
