Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: weird array processing questionby ikegami (Patriarch) |
on May 06, 2011 at 00:00 UTC ( [id://903263]=note: print w/replies, xml ) | Need Help?? |
Permutations (if ordered) or combinations (if unordered). The latter in this case. For choosing two from the list, one could simply use:
But that would be inefficient here. It's O(N**2), whereas the following is O(N):
One can optimise the above to exit as soon as the answer is obvious:
In Section
Seekers of Perl Wisdom
|
|