OK with your idea I came up with this:
#!/usr/bin/perl #program will generate all unique combinations of 4 from a pool of pla +yers #without repeating any pair of players use strict; use Math::Combinatorics; my $count; my %seen; sub trackSeen{ my @players = @{$_[0]}; #For each set of 4 players the following positions are ones we do +not want to see again my @pairs = ($players[0].$players[1], #0,1 $players[0].$players[2], #0,2 $players[0].$players[3], #0,3 $players[1].$players[2], #1,2 $players[1].$players[3], #1,3 $players[2].$players[3] #2,3 ); foreach my $pair (@pairs){ $seen{$pair} = 1; } } sub notSeen{ my @players = @{$_[0]}; my @pairs = ($players[0].$players[1], #0,1 $players[0].$players[2], #0,2 $players[0].$players[3], #0,3 $players[1].$players[2], #1,2 $players[1].$players[3], #1,3 $players[2].$players[3] #2,3 ); foreach my $pair (@pairs){ if (scalar grep /$pair/, keys(%seen) ){ return 0; } } return 1; } my @n = 'A'..'X'; my $comboObj = Math::Combinatorics->new(count => 4, data => [@n]); print "combinations of 4 from: " . join(" ", @n)."\n"; print "-----------------------------" . ("----" x scalar(@n))."\n"; while ( my @combo = $comboObj->next_combination){ if ( notSeen(\@combo) == 1) { print join(', ', @combo) . "\n"; $count++; trackSeen(\@combo); } } print "$count combinations\n";
The magic number for 24 players seems to be 35. I am sure this is not the most efficient way of doing it, but it works. Thanks. Output:
A, B, C, D A, E, F, G A, H, I, J A, K, L, M A, N, O, P A, Q, R, S A, T, U, V B, E, H, K B, F, I, L B, G, J, M B, N, Q, T B, O, R, U B, P, S, V C, E, I, M C, F, H, N C, G, K, O C, J, L, P C, Q, U, W C, R, T, X D, E, J, N D, F, K, P D, G, H, L D, I, O, Q D, M, R, V D, S, T, W E, L, O, S E, P, Q, X F, J, O, T F, M, S, U F, V, W, X G, I, N, R H, M, O, W I, K, S, X J, K, Q, V L, N, U, X 35 combinations

In reply to Re^2: Unique Combos with Math::Combinatorics by ketema
in thread Unique Combos with Math::Combinatorics by ketema

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.