use strict; use warnings; my ($Card,$Lookup,$Feature,$Order); my (@card_ids,$order); # Generate IDs for the cards # And save the order for the cards while(){ chomp; my $card = $_; my @fields = split /\t+/; my $type = 0; my $card_id = ''; foreach (@fields){ $type += 1; unless(defined $Lookup->{$type}{$_}){ $Feature->{$type} += 1; #Add the feature $Lookup->{$type}{$_} = $Feature->{$type}; } $card_id .= $Lookup->{$type}{$_}; } push @card_ids, $card_id; # print "$card_id\n"; $order++; $Order->{$card_id} = $order; $Card->{$order} =$card; } foreach ( @card_ids){ print "$_\t", $Order->{$_},"\n"; } # Get the matching cards @card_ids = sort @card_ids; foreach my $id_1 (@card_ids){ foreach my $id_2 (@card_ids){ next unless $id_1 < $id_2; group: foreach my $id_3 (@card_ids){ next unless $id_2 < $id_3; my $sum = $id_1 + $id_2 + $id_3; foreach (split //,$sum){ next group unless $_ % 3 == 0; #The Alogrithm } print join "\n", map {$Order->{$_}."\t". $Card->{$Order->{$_}}} ($id_1,$id_2,$id_3); print "\n",'x' x 60,"\n"; } } }