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:#!/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";
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |