"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/system-design-primer-primer)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Design a deck of cards"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints and assumptions\n",
"\n",
"* Is this a generic deck of cards for games like poker and black jack?\n",
" * Yes, design a generic deck then extend it to black jack\n",
"* Can we assume the deck has 52 cards (2-10, Jack, Queen, King, Ace) and 4 suits?\n",
" * Yes\n",
"* Can we assume inputs are valid or do we have to validate them?\n",
" return max_under if max_under != -sys.MAXSIZE else min_over\n",
"\n",
" def possible_scores(self):\n",
" \"\"\"Return a list of possible scores, taking Aces into account.\"\"\"\n",
" # ...\n",
"\n",
"\n",
"class Deck(object):\n",
"\n",
" def __init__(self, cards):\n",
" self.cards = cards\n",
" self.deal_index = 0\n",
"\n",
" def remaining_cards(self):\n",
" return len(self.cards) - deal_index\n",
"\n",
" def deal_card():\n",
" try:\n",
" card = self.cards[self.deal_index]\n",
" card.is_available = False\n",
" self.deal_index += 1\n",
" except IndexError:\n",
" return None\n",
" return card\n",
"\n",
" def shuffle(self): # ..."
]
}
],
"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.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
%% Cell type:markdown id: tags:
This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/system-design-primer-primer).
%% Cell type:markdown id: tags:
# Design a deck of cards
%% Cell type:markdown id: tags:
## Constraints and assumptions
* Is this a generic deck of cards for games like poker and black jack?
* Yes, design a generic deck then extend it to black jack
* Can we assume the deck has 52 cards (2-10, Jack, Queen, King, Ace) and 4 suits?
* Yes
* Can we assume inputs are valid or do we have to validate them?