Looking not founding (the problem)
Hi Guys!
I have this little piece of code, that generates an exception if I set NUM_P to lets say 4000 or more.
Code:
#define NUM_P 2300
#define PARTY_NUM 100
#define PEOPLE_PER_PARTY NUM_P/PARTY_NUM
for (a = 1; a<= PARTY_NUM; a++)
{
for (i = PEOPLE_PER_PARTY*(a-1); i < PEOPLE_PER_PARTY*a; i++)
{
for (k = PEOPLE_PER_PARTY*(a-1); k < PEOPLE_PER_PARTY*a -(i-PEOPLE_PER_PARTY*(a-1)); k++)
{
if ( k != 0)
if (bday[i] == bday[k + i])
count++;
}
}
}
This is basically a counter that checks an array to see if 2 int's match.
Before I tried to pirk it up a little the code was like this
Code:
#define NUM_P 2300
#define PARTY_NUM 100
#define PEOPLE_PER_PARTY NUM_P/PARTY_NUM
for (a = 1; a<= PARTY_NUM; a++)
{
for (i = PEOPLE_PER_PARTY*(a-1); i < PEOPLE_PER_PARTY*a; i++)
{
for (k = PEOPLE_PER_PARTY*(a-1); k < PEOPLE_PER_PARTY*a; k++)
{
if ( i != k)
if (bday[i] == bday[k])
count++;
}
}
}
What I tried to do in the first algorithem is to count the array (for example for bday[10] to bday[20] so that we wouldn't count twice, or just plain wrong) because you can see that in the second algorith(second prog.) if let's say 10,14,15,16 match then we would count++ 4*3 = 12 times, but we only had 4 matches so this has to be fixed.
So now to the conclusion, what I'm askin' is if you can scan through it if you can catch the bug, because I've been looking at it for some time now and I'm starting to get delirious. I'll continue debugin' meanwhile any help will be appreciated.
PS: If you happen to find any loopholes in the algorythm be sure to mention them.
Thnx