in reply to Gift Exchange Code
Make two arrays as follows: @array1 = qw/man1 man2 woman3 single1 single2/; and @array2 = qw/woman1 woman2 man3 single3 single4/;
man1 and woman1 are SO to each other, same for man2 and woman2, etc.
Now do a few times push @array2, shift @array2; (less than the number of elements in this array of course). You have now rolled-over this array and you can pair-off the elements of both arrays against each other and guarantee that no SOs will "meet".
The "cheating" is that you cannot find all possible legal combinations in this way, but who would need that?
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|