A poker card is characterized by a suit (“spades”, “hearts”, “diamonds”,
“clubs”) and a rank (, “Jack”, “Queen”, “King” and “Ace”).
Here is the way to define suits in sage:
Define similarly the set Ranks:
The deck of card is the cartesian product of the set of suits by the set of ranks. Define a set Cards accordingly:
Use the method .cardinality() to compute the number of suits, ranks and cards:
Draw a card at random:
Cards are (currently) returned as lists. To be able to build a set of cards, we need them to be hashable. Let’s redefine the set of cards by transforming cards to tuples:
Use Subsets to draw a hand of five cards at random:
Use .cardinality() to compute the number of hands, check the result with binomial:
To go further, see exercises 38, 39, 40 in Calcul Mathématique avec Sage (version 1.0) page 255.
List all the strict partitions of (hint: use
Partitions with max_slope):
List all the vectors of 0 and 1 of length 5 (hint: use IntegerVectors with max_part):
You can also use a cartesian product:
List all the Dyck words of length 6:
Here is the way to print the standard tableaux of size :
Define the set of all the partitions of to
(hint: use
DisjointUnionEnumeratedSets):