Skip to main content

No project description provided

Project description

logo

docsPyPI - VersionTest

shuffle-kit is a Python package for modelling and analyzing playing card shuffles.

It implements several mathematical models of commonly used shuffles that can be composed into complex sequences.

In addition, several utility functions are provided to faciliate analyzing the various shuffle models.

Installation

Dependencies

shuffle-kit requires:

  • Python (>= 3.11)
  • Numpy (>= 1.26.3)

User installation

The easiest way to install shuffle-kit is via pip:

pip install shuffle-kit

Examples

Basic example of using shuffle-kit

from shuffl import gsr, strip, cut, sequence, simulate, Deck
from itertools import accumulate

# Creates a list of integers from 1..52, representing a
# standard deck of 52 cards
deck = Deck(range(1,53))

# Creates a riffle, riffle, strip, riffle, cut shuffle sequence
# with the Gilbert-Shannon-Reeds model for riffle shuffling
shuffle = sequence([gsr, gsr, strip, gsr, cut])

# Simulate the shuffle a 1000 times. For each simulation, the
# deck is reset to the initial order
result = simulate(shuffle, deck, 1000)

# Compute the empirical cumulative density function of the
# original top card, i.e., "1"
ecdf = list(accumulate(result.probability[0]))

# Print the probability that the original top card ("1") is
# found within the top ten cards after shuffling
print(f"Probability of finding '1' within the top ten cards: {ecdf[9]:.2}")

Simulating a guessing game

Here we play a round of the guessing game described in Bayer and Diaconis (1992). Consider a shuffled deck of 52 cards, face down on the table. The task is to guess the top card. After each guess, the top card is turned over and discarded.

If the deck is perfectly shuffled the average number of correct guesses is around 4.5. However, if the deck is riffle shuffled k times, then there exists a conjectural optimal strategy that achives a higher number of correct guesses depending on k.

from shuffl.games import guessing_game
from shuffl import gsr, Deck, sequence

# Creates a list of integers from 1..52, representing a
# standard deck of 52 cards
deck = Deck(range(1, 53))

# Creates a sequence of two riffle shuffles following
# the Gilbert-Shannon-Reeds model
shuffle = sequence([gsr, gsr])

# Run a simulation of the guessing game described in
# Bayer D., Diaconis P. (1992). Trailing the dovetail shuffle to its lair.
# The Annals of Applied Probability, Vol. 2, No. 2, 294-313
correct_guess = guessing_game(deck, shuffle)

# Print the number of correct guesses. On average this should
# be around 19.
print(f"Number of correct guesses: {correct_guess}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shuffle_kit-0.1.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

shuffle_kit-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file shuffle_kit-0.1.3.tar.gz.

File metadata

  • Download URL: shuffle_kit-0.1.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.4 Windows/10

File hashes

Hashes for shuffle_kit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bbf08d14243ff5d14c8ffdfdf3f19676a4a4870162c791535ba2d9cefb7932b7
MD5 158437363075ff0ac4e5b70a3e1e3b61
BLAKE2b-256 9a508f9f3f78a829485dd1802dbab82add7adb2da5aec1f6a28c7307e77a8e0e

See more details on using hashes here.

File details

Details for the file shuffle_kit-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: shuffle_kit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.4 Windows/10

File hashes

Hashes for shuffle_kit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1ccaa65df1b1f64909749eb5e0101c213a47739214d385d44e33a15dfcf8690c
MD5 ad2b00d6d6befdab16106810458d00d3
BLAKE2b-256 e676b2f73202fdca1b18a21b5d7649e5a769ebae1881e9977a49c437c326ae56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page