I’m really new to programming in Objective-C, my background is in labview which is a graphical programming language, I’ve worked with Visual Basic some and HTML/CSS a fair amount as well. I’m trying to figure out the logic to create an array of data for the pattern below. I need the pattern later to extract data from another 2 arrays in a specific order.
I can do it by referencing a = 1, b = 2, c = 3 etc and then creating the array with a, b, c but I want to use a loop so that I don’t have 8 references above the array. These references will be used to generate another generation of data so unless I can get help figuring out the logic I’ll actually end up with 72 references above the array.
// This is the first one which gives the pattern
0 0 0 0 (etc) // 1 1 1 1 // 2 2 2 2
NSMutableArray * expSecondRef_one = [NSMutableArray array];
int a1 = 0;
while (a1 < 9) {
int a2 = 0;
while (a2 < 8) {
NSNumber * a3 = [NSNumber numberWithInt:a1];
[expSecondRef_one addObject:a3];
a2++;
}
a1++;
}
// This is the second one which I’m stumbling over, I am looking for the pattern
1 2 3 4 5 6 7 8 //
0 2 3 4 5 6 7 8 //
0 1 3 4 5 6 7 8 //
0 1 2 4 5 6 7 8 // etc to -> // 0 1 2 3 4 5 6 7
If you run it in a line every 9th number is -1 but I don’t know how to do that over a pattern of 8.
Thanks in advance!
Graham
I think you’re looking for something like :
I left out the code to actually insert the numbers into the array.
I’m not totally clear on how you’re using this array, but if this is just an order of indexes to access data from another group of arrays, you may be able to skip the first set of arrays and just use this loop to access your data later.
–edit–
If I’m understanding you correctly, you want to compare each index in an array of 9 numbers to every other index, then store the results in an array. If that’s the case, you could just do something like this: