#! /usr/bin/perl -w use strict; my @array = @ARGV ? @ARGV : qw/mix up these words in new ways/; sub fac { my $nr = shift; return 1 if $nr < 2; return $nr*fac($nr-1); } my %seen; my $max = fac(scalar @array); my $nr = 0; while( $nr < $max ) { my $need_combo = 1; my @combo; while( $need_combo ) { for( my $i = 0; $i < scalar @array; ++$i ) { $combo[$i] = $array[ rand scalar @array ]; } my %unique; my $unique = 1; for my $c ( @combo ) { if( ++$unique{$c} > 1 ) { $unique = 0; } } if( $unique == 1 ) { $need_combo = 0; } } if( exists $seen{ "@combo" } ) { next; } else { local $" = "\t"; print "@combo\n"; } ++$seen{"@combo"}; ++$nr; }