.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/combinatorics/counting/plot_01_poker_hands.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_combinatorics_counting_plot_01_poker_hands.py: Counting poker hands ========================= Counts 5-card poker hands and a few hand types, and cross-checks the count against brute-force enumeration for a smaller deck. .. GENERATED FROM PYTHON SOURCE LINES 10-12 .. code-block:: Python from mathematicskit.combinatorics import combinations_count, generate_combinations, multinomial_coefficient .. GENERATED FROM PYTHON SOURCE LINES 13-15 Total 5-card hands from a standard 52-card deck ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python total_hands = combinations_count(52, 5) print(f"total 5-card hands: {total_hands}") .. rst-class:: sphx-glr-script-out .. code-block:: none total 5-card hands: 2598960 .. GENERATED FROM PYTHON SOURCE LINES 20-22 Number of ways to deal a full house (3 of one rank, 2 of another) ------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python full_houses = combinations_count(13, 1) * combinations_count(4, 3) * combinations_count(12, 1) * combinations_count(4, 2) print(f"full houses: {full_houses} (probability {full_houses / total_hands:.6f})") .. rst-class:: sphx-glr-script-out .. code-block:: none full houses: 3744 (probability 0.001441) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Cross-check via brute-force enumeration on a small 8-card deck ------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python small_deck = list(range(8)) hands = generate_combinations(small_deck, r=3) print(f"\nC(8,3) = {combinations_count(8, 3)}, generated {len(hands)} hands") .. rst-class:: sphx-glr-script-out .. code-block:: none C(8,3) = 56, generated 56 hands .. GENERATED FROM PYTHON SOURCE LINES 35-37 Multinomial coefficient: ways to deal a 13-card deck into 4 equal hands ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python deals = multinomial_coefficient(12, [3, 3, 3, 3]) print(f"ways to split 12 cards into 4 groups of 3: {deals}") .. rst-class:: sphx-glr-script-out .. code-block:: none ways to split 12 cards into 4 groups of 3: 369600 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 seconds) .. _sphx_glr_download_api_gallery_combinatorics_counting_plot_01_poker_hands.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_poker_hands.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_poker_hands.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_poker_hands.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_