The object of the game is to identify the 6 'Sets', of three cards each, from 12 cards laid out on the screen. Each card has a variation of the following four features:
Update 1:
Approach:I tried manually but didn't get all the 6 sets, so I decided to write a code for the same. The first idea came to my mind to create a unique ID for each card. ID should consists an entry for the feature. Instead of putting all the features into hash to read in program, I decided to generate the IDs as I get the data. So
Red Diamond 2 openwill have ID: 2121, with each digit representing the feature in order. Similarly,
Purple Diamond 1 openwill have ID: 3131.
Interesting part was to decide the match: I noticed that if I pick any two of the ID and third matching ID should be unique. Example, 1112 and 2213, then the third ID must be 3311. (12=>3 (different), 12=>3(different), 11=>1(unique), 23=>1(different)) If it is there in the given cards, we have found the set. Coming with calculation of 3rd ID was intersting, as I noticed that digits in the sum of each matching IDs (first,second and third) are even divisor of '3'. This algorithm, I found very interesting.
Thanks to halley and demerphq in chatterbox for interesting suggestions.
__DATA__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(<DATA>){ 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"; } } }
Green Diamond 3 open Red Squiggle 2 open Red Oval 2 solid Purple Diamond 2 open Red Squiggle 1 open Green Oval 3 solid Green Squiggle 1 open Purple Diamond 1 open Red Squiggle 2 stripped Red Diamond 3 stripped Green Oval 2 open Red Diamond 2 openOutput:
======================================= 1 Green Diamond 3 open 7 Green Squiggle 1 open 11 Green Oval 2 open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 Green Diamond 3 open 12 Red Diamond 2 open 8 Purple Diamond 1 open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 6 Green Oval 3 solid 9 Red Squiggle 2 stripped 8 Purple Diamond 1 open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 11 Green Oval 2 open 2 Red Squiggle 2 open 4 Purple Diamond 2 open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 10 Red Diamond 3 stripped 5 Red Squiggle 1 open 3 Red Oval 2 solid xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 12 Red Diamond 2 open 9 Red Squiggle 2 stripped 3 Red Oval 2 solid xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxartist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sets Puzzle
by halley (Prior) on Jul 08, 2003 at 18:44 UTC |