Created
August 29, 2021 20:40
-
-
Save johngrant/106e5e36689e3077480dc21e8c2b2233 to your computer and use it in GitHub Desktop.
Total Black Jack Hand.ipynb
This file contains 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Total Black Jack Hand.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyPEcuda2KQC3/lalAI4c/uR", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/johngrant/106e5e36689e3077480dc21e8c2b2233/total-black-jack-hand.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "6fPL6Nvfdx2S", | |
"outputId": "3119e9e0-af54-431a-bf9b-742a655d1abc" | |
}, | |
"source": [ | |
" def total(hand):\n", | |
" i = 0\n", | |
" base = 0\n", | |
" numTotal = sum([int(i) for i in hand if i.isdigit()])\n", | |
" faceTotal = len([i for i in hand if i in ['J','Q','K']]) * 10\n", | |
" base = numTotal + faceTotal\n", | |
" aces = len([a for a in hand if a in ['A']])\n", | |
" \n", | |
" total = base + aces\n", | |
" elevens = 0\n", | |
" while total < 21 and elevens <= aces:\n", | |
" if (base + (elevens*11) + (aces-elevens)) > 21:\n", | |
" break\n", | |
" total = base + (elevens*11) + (aces-elevens)\n", | |
" elevens += 1\n", | |
"\n", | |
" return total\n", | |
"\n", | |
" # A can be 1 or 11\n", | |
" # A,A can be 2, 13, or 22\n", | |
" # A,A,A can be 3, 13, 23, 33,\n", | |
" # A,A,A,A can be 4, 14, 24, 34, 44\n", | |
" \n", | |
"print(\"1,11: {0}\".format(total(['1','11'])))\n", | |
"print(\"A, J: {0}\".format(total(['A','J'])))\n", | |
"print(\"9, 7, K: {0}\".format(total(['9','7', 'K'])))\n", | |
"print(\"A, A, J: {0}\".format(total(['A','A', 'J'])))\n", | |
"print(\"A, 9, J: {0}\".format(total(['A','9', 'J'])))\n", | |
"print(\"A, A, A, J: {0}\".format(total(['A','A', 'A', 'J'])))\n", | |
"print(\"A, A, A, A, J: {0}\".format(total(['A','A', 'A', 'A', 'J'])))\n", | |
"\n" | |
], | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1,11: 12\n", | |
"A, J: 21\n", | |
"9, 7, K: 26\n", | |
"A, A, J: 12\n", | |
"A, 9, J: 20\n", | |
"A, A, A, J: 13\n", | |
"A, A, A, A, J: 14\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "O43WzsSBd7Vk" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment