# 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:** 13

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 4, 2020, 7:07pm UTC](https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366/13 "2020-07-04T19:07:21Z")

</div>

> [@whistlinpete](#):
>
> I gather I create a data array in which to produce all the possible combinations but I can’t figure out how to do that.

This may not answer your questions but will give you something to think about. 🙂

You already have all the possible combinations… you just have to think in binary (and hexadecimal) and extract the bits.

Then wield these bits as you desire to unleash your creative vision.

```auto
  for(int i=0; i<64; i++)
    {
    println(binary(i));
    }

```

Partial code to get you started:

```auto
void setup() 
  {
  size(100, 160);
  colorMode(RGB, 1); // Just using black 0 and white 1
  
  for(int i=0; i<16; i++)
    {
    println(binary(i));
    }
  
  for(int i=0; i<16; i++)
    {
    int a, b;
    
    a = i & 0x01;
    b = (a > 0) ? 1 : 0;
    print(b);
    fill(b);
    circle(20, i*10+5, 10);
    
    a = i & 0x02;
    b = (a > 0) ? 1 : 0;
    print(b);
    fill(b);
    circle(30, i*10+5, 10);
    
    a = i & 0x04;
    b = (a > 0) ? 1 : 0;
    print(b);
    fill(b);
    circle(40, i*10+5, 10);
    
    a = i & 0x08;
    b = (a > 0) ? 1 : 0;
    println(b);
    fill(b);
    circle(50, i*10+5, 10);
    }       
  }

```

References:

> **[?: (conditional) / Reference](https://processing.org/reference/conditional.html)**
>
> A shortcut for writing an if and else structure. The conditional operator, ?: is sometimes called the ternary operator, an operator that takes three arguments. If the test …

> **[& (bitwise AND) / Reference](https://processing.org/reference/bitwiseAND.html)**
>
> Compares each corresponding bit in the binary representation of the values. For each comparison two 1's yield 1, 1 and 0 yield 0, and two 0's yield 0. This is easy to see when we look at the binary re…

> **[colorMode() / Reference](https://processing.org/reference/colorMode_.html)**
>
> Changes the way Processing interprets color data. By default, the parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using t…

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b41372ddd64002575f88283bc973240d458a630e.png)

`:)`

---

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