(no subject)
Sep. 22nd, 2011 11:04 pmI do not like the Allman style, either.
I would write something more here, but... *grumble grumble* (The logical part of myself is even a bit surprised at how much I dislike it.)
I would write something more here, but... *grumble grumble* (The logical part of myself is even a bit surprised at how much I dislike it.)
no subject
Date: 2011-10-06 09:27 pm (UTC)Alas!
I don't think recursion can be used here, but I did notice a repeated expression that I can place in a separate set of loops, to reduce the main one to nine loops deep.
I was thinking more generally. Say you have something like:
for (int a = minA; a < maxA; ++a) { for (int b = minB; b < maxA; ++b) { ... ultimate_value = f(ultimate_value, a, b, ...); } }Then you could do this recursively by defining a maximum, minimum, and current array, e.g.
int minima[N] = {minA, minB, ...};
int maxima[N] = {maxA, maxB, ...};
int current[N];
and then you can recurse:
void lotsaloops(int current_position, int max_position, int & ultimate_value, int * minima, int * maxima, int * current) { if (current_position == max_position) { ultimate_value = f(ultimate_value, current[0], current[1], ...); } else { for (current[current_position] = minima[current_position]; current[current_position] < maxima[current_position]; ++current[current_position]) { lotsaloops(current_position+1, max_position, ultimate_value, minima, maxima, current); } } }... but if you're going that route, I imagine you'll get better results by moving to a functional language and using functions that work on functions. Doing this kind of "virtual looping" can get quite ugly, as well, if you need to calculate things at intermediate loop levels.
no subject
Date: 2011-10-10 01:58 am (UTC)Anyway, it looks like doing it that way sacrifices readability for brevity, so it doesn't seem worthwhile here. I can see it being the only viable option when you don't know beforehand how many loops deep your program will go, however.
no subject
Date: 2011-10-10 08:40 pm (UTC)And congrats! I thought the zero meant that you couldn't use your approach at all, not that your implementation was wrong :)
no subject
Date: 2011-10-11 12:54 am (UTC)No, your first thought was correct, but I found a different set of invariants that did give a nonzero bracket.