in reply to nested combinations: algorithm advice?
chomp(my @lines = <DATA>); my %seen; for my $line1 (@lines) { for my $line2 (grep $_ ne $line1, @lines) { if (1 < matches($line1, $line2)) { $seen{ join ' and ', sort $line1, $line2 } = 1; } } } print "$_\n" for keys %seen; sub matches { my ($line1, $line2) = @_; my %words1 = map {$_ => 1} split /_/, $line1; my $matches = 0; $matches += ($words1{$_}||0) for split /_/, $line2; return $matches; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: nested combinations: algorithm advice?
by revdiablo (Prior) on Sep 22, 2004 at 16:44 UTC | |
by Jasper (Chaplain) on Sep 22, 2004 at 16:54 UTC | |
by revdiablo (Prior) on Sep 22, 2004 at 17:07 UTC |