Loading...
Logo
Processing Forum
void setup(){
 int[] a = new int[10]; int i=1,c=1; 
while(i<a.length){ 
if(c%4==0){
 a[i]=c-a[i-1]; i++; }
 c++;
 }
 for(int j=0;j<a.length-1;j++) 
print(a[j]+","); print(a[i-1]+"."); 
}


Replies(3)

Dunno! But what about some formatting twist to make it harder:  
Copy code
    final byte NUM = 10;
    int[] a = new int[NUM];
    
    for (int c = 0, i = 1; i != NUM;)  if ( (++c & 3) == 0 )  a[i] = c - a[i++ - 1];
    
    for (int j = 0; j != NUM - 1; print(a[j++] + ", "));
    
    print(a[NUM - 1] + ".");
    
    exit();
    

Reformatted:
Copy code
  1. void setup() {
  2.   int[] a = new int[10];
  3.   int i=1, c=1;
  4.  
  5.   while (i<a.length) {
  6.     if (c%4==0) {
  7.       a[i]=c-a[i-1];
  8.       i++;
  9.     }
  10.  
  11.     c++;
  12.   }
  13.  
  14. println(a);
  15. /*
  16.   for (int j=0;j<a.length-1;j++)
  17.     print(a[j]+",");
  18.   print(a[i-1]+".");
  19. */
  20. }
Output:
[0] 0
[1] 4
[2] 4
[3] 8
[4] 8
[5] 12
[6] 12
[7] 16
[8] 16
[9] 20

Not sure if that's the expected result or what interest it has.

 int[] a = new int[10]; 
make an array of integers and call it "a" and give it 10 pigeonholes

int i=1,c=1; 
make two integers i and c and set them equal to 1

while(i<a.length)
while i < length of the array a, so less than 10
if(c%4==0)
if c modulo 4 is 0, or if c is an integer multiple of 4 (4, 8, 12 ...)
{
 a[i] = c - a[i-1];
make the ith entry of the array a equal to c - (i-1)th entry in the array a 
i++; }
 c++;
add 1 to i and add 1 to c
 }
 for(int j=0;j<a.length-1;j++)
for j equaling the values 0, 1, 2, ... 9 in turn
print(a[j]+","); 
print(a[i-1]+"."); 
print these things: the jth value in the array a and the (i-1)th value in the array a
}

gotoloop's joking aside, it's appallingly formated
void setup()
{
 int[] a = new int[10];
 int i = 1;
 int c = 1; 

while(i < a.length)
 if(c % 4 = =0)
 {
   a[i] = c - a[i - 1];
   i++; 
 }
 c++;
 }
 for(int j = 0; j < a.length - 1; j++) 
{
  print(a[j] + ","); 
  print(a[i - 1] + "."); 
}
}