# Iterate once and only once through all the possible configurations of an array

**URL:** <https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366>\
**Category:** Coding Questions\
**Created:** [July 3, 2020, 7:37pm UTC](https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366 "2020-07-03T19:37:07Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [July 6, 2020, 5:28am UTC](https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366/17 "2020-07-06T05:28:27Z")

</div>

> all the possible configurations of an array

If by this you mean all the permutations, then check out [Heap’s algorithm](https://en.wikipedia.org/wiki/Heap%27s_algorithm) – and a recent implementation posted to the forum, here:

> [@Storing all index permutations with Heap's algorithm](https://discourse.processing.org/t/storing-all-index-permutations-with-heaps-algorithm/22326):
>
> Hi, I am new on Processing and I am struggling with Java. I am trying to use [Heap’s algorithm](https://en.wikipedia.org/wiki/Heap%27s_algorithm#Details_of_the_algorithm) to get the list of all the permutations of numbers. I want to store that list so I wan use it as a matrix for animation. I have tried many different ways and types but I can’t fill it correctly. As I am stuck, I would appreciate some help. Here what I have: // https://en.wikipedia.org/wiki/Heap%27s\_algorithm#Details\_of\_the\_algorithm void heapPermutations(int k, IntList l, ArrayList\<IntList\> a) { …

---

_[View the full topic](https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366)._
