-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsim.pde
42 lines (36 loc) · 939 Bytes
/
sim.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void loopThrough(int[] arr){
int totLen = 1;
for(int i = 0; i < arr.length; i++)
totLen *= arr[i];
System.out.println("Total Length: " + totLen);
String name = "arr";
int[] tArr = new int[arr.length];
System.arraycopy( arr, 0, tArr, 0, arr.length );
for(int i = 0; tArr.length > i; i++)
tArr[i] = 0;
int count = 0;
boolean finished = false;
while(!finished){
count++;
System.out.print(count + " => " + name);
for(int i = 0; i < tArr.length; i++)
System.out.print("[" + tArr[i] + "]");
System.out.print("; ");
tArr[tArr.length-1]++;
tArr[tArr.length-1] = tArr[tArr.length-1] % arr[tArr.length-1];
for(int c = (tArr.length-1); tArr[c]==0;){
tArr[c] = 0;
c--;
if(c < 0){
finished = true;
break;
}
tArr[c]++;
tArr[c] = tArr[c]%arr[c];
}
}
}
void setup(){
int[] test = {3,4,5};
loopThrough(test);
}