|Perl Monk, Perl Meditation|
Re: recursive array searchby Rhys (Pilgrim)
|on Oct 01, 2004 at 19:46 UTC||Need Help??|
So if I read this correctly, you're comparing each element in the array to every other element of the array (but not to itself). So the two foreach loops make sense (mostly). The if statement you used would probably be clearer like this (IMHO):
...but that's just me. For the rest of your question, I think you're going to have to be clearer on what pairs of data match. I can tell you now that it's probably going to involve something along these lines:
Also, if you use for loops instead of foreach loops, you could make sure that the inner loop always starts at the same index as the outer loop (plus one), which should cut your runtime roughly in half. (Unless the a<=>b comparison is not the same as the b<=>a comparison, in which case, keep the foreach loops.)
More info, please?
Update: Okay, I read the code some more, and it looks like the first part has a number, and when you compare, you're looking for a multiple of that number (including zero). That's simple modulo arithmetic. You can do this to catch the first part:
We say, 'if not (math)' because if the first part modulo the second part comes out even, the return will be zero. Hence 'not' to make the test true.
Could still use some more information on what should and shouldn't match, though. I'm just guessing, here.