Created
May 25, 2024 22:27
-
-
Save archey347/00b05247d862c7eaa09955b4fe05d092 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import random" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "\n", | |
| "def get_expected(deck, scoreMap, draw_n_cards, rounds):\n", | |
| "\n", | |
| " if rounds == 0:\n", | |
| " return 0\n", | |
| "\n", | |
| " sum_score = 0\n", | |
| "\n", | |
| " for rounds in range(0, rounds):\n", | |
| "\n", | |
| " score = 0\n", | |
| " random.shuffle(deck)\n", | |
| "\n", | |
| " for i in range(0, draw_n_cards):\n", | |
| " card = deck[i]\n", | |
| " score += scoreMap[card]\n", | |
| "\n", | |
| " sum_score += score\n", | |
| "\n", | |
| " return sum_score / rounds\n", | |
| "\n", | |
| "\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 22, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Face cards = 10\n", | |
| "111.18042718042717\n", | |
| "\n", | |
| "Face cards J = 11, Q = 12, K = 13\n", | |
| "119.02167102167103\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "deck = [\"A\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"J\", \"Q\", \"K\"] * 4\n", | |
| "\n", | |
| "scoreMapA = {\n", | |
| " \"A\": 1,\n", | |
| " \"2\": 2,\n", | |
| " \"3\": 3,\n", | |
| " \"4\": 4,\n", | |
| " \"5\": 5,\n", | |
| " \"6\": 6,\n", | |
| " \"7\": 7,\n", | |
| " \"8\": 8,\n", | |
| " \"9\": 9,\n", | |
| " \"10\": 10,\n", | |
| " \"J\": 10,\n", | |
| " \"Q\": 10,\n", | |
| " \"K\": 10\n", | |
| "}\n", | |
| "\n", | |
| "scoreMapB = {\n", | |
| " \"A\": 1,\n", | |
| " \"2\": 2,\n", | |
| " \"3\": 3,\n", | |
| " \"4\": 4,\n", | |
| " \"5\": 5,\n", | |
| " \"6\": 6,\n", | |
| " \"7\": 7,\n", | |
| " \"8\": 8,\n", | |
| " \"9\": 9,\n", | |
| " \"10\": 10,\n", | |
| " \"J\": 11,\n", | |
| " \"Q\": 12,\n", | |
| " \"K\": 13\n", | |
| "}\n", | |
| "print(\"Face cards = 10\")\n", | |
| "print(get_expected(deck, scoreMapA, 17, 1000000))\n", | |
| "print()\n", | |
| "print(\"Face cards J = 11, Q = 12, K = 13\")\n", | |
| "print(get_expected(deck, scoreMapB, 17, 1000000))\n" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.12.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment