Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Solver for the game "Set" matches three times

by pc88mxer (Vicar)
on Jul 15, 2008 at 16:04 UTC ( [id://697748]=note: print w/replies, xml ) Need Help??


in reply to Solver for the game "Set" matches three times

You can use PDL to simplify these calculations. As you have it, a card is just an array of four numbers mod 3. You are using 1, 2 and 3 but you can also use 0, 1 and 2.

Then a set is just three cards X, Y, Z where X+Y+Z = (0,0,0,0) mod 3.

use PDL; sub is_a_set { all (($_[0] + $_[1] + $_[2]) % 3) == 0; } sub third_card { (pdl(3,3,3,3)-$_[0]-$_[1]) % 3; } my $X = pdl(0,1,2,2); my $Y = pdl(0,2,2,1); my $Z = pdl(0,0,2,0); if (is_a_set($X, $Y, $Z)) { print "$X, $Y and $Z form a set\n"; } else { print "$X, $Y and $Z do not form a set\n"; } print "To form a set with $X and $Y you need: ", third_card($X, $Y), " +\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-23 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found