Skip to main content

Penney's game

Project description

Penney's Game

built with Python3 GitHub repo size PyPI version

Overview

Penney's game, named after its inventor Walter Penney, is a binary (head/tail) sequence generating game between two or more players. Player A selects a sequence of heads and tails (of length 3 or larger), and shows this sequence to player B. Player B then selects another sequence of heads and tails of the same length. Subsequently, a fair coin is tossed until either player A's or player B's sequence appears as a consecutive subsequence of the coin toss outcomes. The player whose sequence appears first wins. Here we have a clone of this game that I wrote during coronavirus quarantine days.

ℹ️ In playing with the computer, the computer selects its sequence randomly

ℹ️ For details about how the winning probability is calculated, you can visit Penney’s game between many players paper

PyPI Counter
GitHub Stars
Branch master dev
CI
Code Quality CodeFactor

Installation

Source Code

PyPI

Exe Version (Windows)

How to Play

ℹ️ You can use penney, python -m penney or Penney.exe to run this program

Screen Record

Screen Record

Try Penney in Your Browser!

You can play Penney's game online in interactive Jupyter Notebooks via the Binder or Colab services! Try it out now!:

Binder

Google Colab

  • Open Notebook.ipynb

Contribution

Changes and improvements are more than welcome! ❤️ Feel free to fork and open a pull request.

Please consider the following :

  1. Fork it!
  2. Create your feature branch (under dev branch)
  3. Add your functions/methods to proper files
  4. Add standard docstring to your functions/methods
  5. Add tests for your functions/methods (test cases in test folder)
  6. Pass all CI tests
  7. Update CHANGELOG.md
    • Describe changes under [Unreleased] section
  8. Submit a pull request into dev (please complete the pull request template)

Issues & Bug Reports

Just open an issue and describe it. I'll check it ASAP! or send an email to me@sepand.tech.

  • Please complete the issue template

References

1- Penney, Walter. "Problem 95: penney-ante." Journal of Recreational Mathematics 7 (1974): 321.
2- Zajkowski, Krzysztof. "Penney's game between many players." arXiv preprint arXiv:1212.3973 (2012).
3- Guy, R. K., and John Horton Conway. Winning Ways for your Mathematical Plays. Academic Press, London, 1982.
4- Humble, Steve, and Yutaka Nishiyama. "Humble-Nishiyama Randomness Game-A New Variation on Penney's Coin Game." (2010).

Show Your Support

Star This Repo

Give a ⭐️ if this project helped you!

Donate to Our Project

Bitcoin

1KtNLEEeUbTEK9PdN6Ya3ZAKXaqoKUuxCy

Ethereum

0xcD4Db18B6664A9662123D4307B074aE968535388

Litecoin

Ldnz5gMcEeV8BAdsyf8FstWDC6uyYR6pgZ

Doge

DDUnKpFQbBqLpFVZ9DfuVysBdr249HxVDh

Tron

TCZxzPZLcJHr2qR3uPUB1tXB6L3FDSSAx7

Ripple

rN7ZuRG7HDGHR5nof8nu5LrsbmSB61V1qq

Binance Coin

bnb1zglwcf0ac3d0s2f6ck5kgwvcru4tlctt4p5qef

Tether

0xcD4Db18B6664A9662123D4307B074aE968535388

Dash

Xd3Yn2qZJ7VE8nbKw2fS98aLxR5M6WUU3s

Stellar

GALPOLPISRHIYHLQER2TLJRGUSZH52RYDK6C3HIU4PSMNAV65Q36EGNL

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

0.5 - 2025-09-26

Added

  • SECURITY.md

Changed

  • Logo updated
  • Python typing features added to all modules
  • det function renamed to calculate_determinant
  • line function renamed to print_line
  • description function renamed to print_description
  • left_justify function renamed to justify_left
  • justify function renamed to justify_text
  • seq_generator function renamed to generate_sequence
  • C_calc function renamed to calculate_C
  • prob_calc function renamed to calculate_probability
  • print_prob function renamed to print_probability
  • game function renamed to run_game
  • check_seq function renamed to validate_sequence
  • get_seq function renamed to get_sequences
  • get_len function renamed to get_length
  • check_name function renamed to validate_name
  • print_seq function renamed to print_sequence
  • computer_seq_gen function renamed to generate_computer_sequence
  • player_filter function renamed to filter_players
  • menu function renamed to menu_handler
  • print_probability function bug fixed
  • get_names function bug fixed
  • Test system modified
  • Build script updated
  • CLI mode updated
  • Notebook.ipynb updated
  • codecov removed from dev-requirements.txt
  • Python 3.5 support dropped
  • Python 3.6 support dropped
  • Python 3.10 added to test.yml
  • Python 3.11 added to test.yml
  • Python 3.12 added to test.yml
  • Python 3.13 added to test.yml
  • README.md modified
  • String templates modified

0.4 - 2021-05-19

Added

  • requirements-splitter.py
  • print_seq function

Changed

  • Test system modified
  • game function modified
  • Menu optimized

0.3 - 2020-04-16

Changed

  • README.md modified
  • Minor issues fixed
  • print_result function tie condition bug fixed

0.2 - 2020-04-08

Added

  • det function
  • prob_calc function
  • print_prob function
  • C_calc function
  • Notebook.ipynb file
  • build_unix.sh file
  • Github action

Changed

  • README.md modified
  • version_check.py updated

0.1 - 2020-03-21

Added

  • Player mode
  • Computer mode
  • Exe version
  • Test system

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

penney-0.5.tar.gz (255.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

penney-0.5-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file penney-0.5.tar.gz.

File metadata

  • Download URL: penney-0.5.tar.gz
  • Upload date:
  • Size: 255.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for penney-0.5.tar.gz
Algorithm Hash digest
SHA256 c7d5d9e702c3a9bd8ec5ed9c3b528fc00c06bc0f208e4ed4400d63eec89ec560
MD5 4e6fe20d2389cd0365edd17f7dcee423
BLAKE2b-256 bbc58ebb50ac891988e4ebc96f8d73f89f2dcbb00f976e4d8137e792f3ba5803

See more details on using hashes here.

File details

Details for the file penney-0.5-py3-none-any.whl.

File metadata

  • Download URL: penney-0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for penney-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 66063fdbb3a54e6cebb12c45f58a48714e851b7139f417d9c32238709e406953
MD5 4055a0fcfc4a3746e025cb6bb60dd4e8
BLAKE2b-256 1cce9c390a0a88e2d29a869f966605bda35e0de0a30c1838a62670cbbecf1f67

See more details on using hashes here.

Supported by

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