|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": { |
| 7 | + "collapsed": true |
| 8 | + }, |
| 9 | + "outputs": [], |
| 10 | + "source": [ |
| 11 | + "import collections\n", |
| 12 | + "\n", |
| 13 | + "Card = collections.namedtuple('Card', ['rank', 'suit'])\n", |
| 14 | + "\n", |
| 15 | + "class FrenchDeck:\n", |
| 16 | + " ranks = [str(n) for n in range(2, 11)] + list('JQKA')\n", |
| 17 | + " suits = 'spades diamonds clubs hearts'.split()\n", |
| 18 | + "\n", |
| 19 | + " def __init__(self):\n", |
| 20 | + " self._cards = [Card(rank, suit) for suit in self.suits\n", |
| 21 | + " for rank in self.ranks]\n", |
| 22 | + "\n", |
| 23 | + " def __len__(self):\n", |
| 24 | + " return len(self._cards)\n", |
| 25 | + "\n", |
| 26 | + " def __getitem__(self, position):\n", |
| 27 | + " return self._cards[position]\n" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": 36, |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [ |
| 35 | + { |
| 36 | + "data": { |
| 37 | + "text/plain": [ |
| 38 | + "52" |
| 39 | + ] |
| 40 | + }, |
| 41 | + "execution_count": 36, |
| 42 | + "metadata": {}, |
| 43 | + "output_type": "execute_result" |
| 44 | + } |
| 45 | + ], |
| 46 | + "source": [ |
| 47 | + "deck1=FrenchDeck()\n", |
| 48 | + "len(deck1)" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "markdown", |
| 53 | + "metadata": {}, |
| 54 | + "source": [ |
| 55 | + "We could select Aces by starting from 12, and then skipping 13 cards afterwards:" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "code", |
| 60 | + "execution_count": 15, |
| 61 | + "metadata": {}, |
| 62 | + "outputs": [ |
| 63 | + { |
| 64 | + "name": "stdout", |
| 65 | + "output_type": "stream", |
| 66 | + "text": [ |
| 67 | + "[Card(rank='A', suit='spades'), Card(rank='A', suit='diamonds'), Card(rank='A', suit='clubs'), Card(rank='A', suit='hearts')]\n" |
| 68 | + ] |
| 69 | + } |
| 70 | + ], |
| 71 | + "source": [ |
| 72 | + "print(deck1[12::13])" |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + "cell_type": "code", |
| 77 | + "execution_count": 37, |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "suits=[str(n) for n in range(2, 11)] + list('JQKA')\n", |
| 82 | + "ranks='spades diamonds clubs hearts'.split()" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "code", |
| 87 | + "execution_count": 59, |
| 88 | + "metadata": {}, |
| 89 | + "outputs": [], |
| 90 | + "source": [ |
| 91 | + "deck2=[(rank, suit) for suit in suits for rank in ranks]" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 60, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "name": "stdout", |
| 101 | + "output_type": "stream", |
| 102 | + "text": [ |
| 103 | + "None\n" |
| 104 | + ] |
| 105 | + } |
| 106 | + ], |
| 107 | + "source": [ |
| 108 | + "from random import shuffle\n", |
| 109 | + "print(shuffle(deck2))" |
| 110 | + ] |
| 111 | + }, |
| 112 | + { |
| 113 | + "cell_type": "code", |
| 114 | + "execution_count": 61, |
| 115 | + "metadata": {}, |
| 116 | + "outputs": [ |
| 117 | + { |
| 118 | + "name": "stdout", |
| 119 | + "output_type": "stream", |
| 120 | + "text": [ |
| 121 | + "[('clubs', '5'), ('hearts', '2'), ('spades', '2'), ('diamonds', '9'), ('diamonds', '5'), ('diamonds', 'A'), ('diamonds', '7'), ('diamonds', '8'), ('spades', '10'), ('diamonds', '2'), ('spades', 'K'), ('spades', '8'), ('diamonds', 'K'), ('spades', 'Q'), ('spades', '7'), ('diamonds', '4'), ('spades', '6'), ('hearts', 'J'), ('spades', '3'), ('spades', '4'), ('hearts', '6'), ('spades', '5'), ('clubs', 'A'), ('hearts', '8'), ('clubs', 'J'), ('hearts', '10'), ('spades', 'A'), ('clubs', '10'), ('clubs', '4'), ('hearts', '5'), ('clubs', '7'), ('clubs', 'Q'), ('diamonds', '6'), ('diamonds', '10'), ('spades', 'J'), ('hearts', '9'), ('clubs', '3'), ('hearts', 'K'), ('clubs', '6'), ('hearts', '7'), ('hearts', 'A'), ('clubs', 'K'), ('diamonds', '3'), ('hearts', '3'), ('diamonds', 'J'), ('clubs', '8'), ('hearts', '4'), ('clubs', '2'), ('spades', '9'), ('diamonds', 'Q'), ('hearts', 'Q'), ('clubs', '9')]\n" |
| 122 | + ] |
| 123 | + } |
| 124 | + ], |
| 125 | + "source": [ |
| 126 | + "print(deck2)" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": 119, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [ |
| 134 | + { |
| 135 | + "name": "stdout", |
| 136 | + "output_type": "stream", |
| 137 | + "text": [ |
| 138 | + "[('spades', 'K'), ('diamonds', 'K'), ('hearts', '6'), ('clubs', '3'), ('hearts', '7'), ('diamonds', 'Q'), ('diamonds', '7'), ('spades', 'A'), ('diamonds', '6'), ('diamonds', '8'), ('clubs', '2'), ('clubs', 'A'), ('diamonds', '5'), ('diamonds', 'J'), ('clubs', '5'), ('diamonds', '2'), ('spades', '7'), ('clubs', 'K'), ('spades', 'J'), ('hearts', '2'), ('spades', '2'), ('hearts', '9'), ('spades', '5'), ('diamonds', '10'), ('clubs', '9'), ('spades', '10'), ('clubs', '8'), ('spades', '3'), ('diamonds', '4'), ('clubs', '4'), ('clubs', '6'), ('spades', '8'), ('spades', '4'), ('spades', '9'), ('spades', 'Q'), ('hearts', 'Q'), ('clubs', '7'), ('spades', '6'), ('hearts', 'J'), ('hearts', '4'), ('hearts', 'A'), ('clubs', 'J'), ('diamonds', 'A'), ('clubs', '10'), ('hearts', '5'), ('hearts', '3'), ('diamonds', '9'), ('hearts', '8'), ('hearts', 'K'), ('diamonds', '3'), ('clubs', 'Q'), ('hearts', '10')]\n" |
| 139 | + ] |
| 140 | + } |
| 141 | + ], |
| 142 | + "source": [ |
| 143 | + "shuffle(deck2)\n", |
| 144 | + "print(deck2)" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 120, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [ |
| 153 | + "board=deck2[4::5][0:3]" |
| 154 | + ] |
| 155 | + }, |
| 156 | + { |
| 157 | + "cell_type": "code", |
| 158 | + "execution_count": 121, |
| 159 | + "metadata": { |
| 160 | + "collapsed": true |
| 161 | + }, |
| 162 | + "outputs": [], |
| 163 | + "source": [ |
| 164 | + "hee=deck2[1::5][0:2]\n", |
| 165 | + "john=deck2[2::5][0:2]\n", |
| 166 | + "jieun=deck2[3::5][0:2]" |
| 167 | + ] |
| 168 | + }, |
| 169 | + { |
| 170 | + "cell_type": "code", |
| 171 | + "execution_count": 122, |
| 172 | + "metadata": {}, |
| 173 | + "outputs": [ |
| 174 | + { |
| 175 | + "data": { |
| 176 | + "text/plain": [ |
| 177 | + "([('diamonds', 'K'), ('diamonds', '7')],\n", |
| 178 | + " [('hearts', '6'), ('spades', 'A')],\n", |
| 179 | + " [('clubs', '3'), ('diamonds', '6')])" |
| 180 | + ] |
| 181 | + }, |
| 182 | + "execution_count": 122, |
| 183 | + "metadata": {}, |
| 184 | + "output_type": "execute_result" |
| 185 | + } |
| 186 | + ], |
| 187 | + "source": [ |
| 188 | + "hee,john,jieun" |
| 189 | + ] |
| 190 | + }, |
| 191 | + { |
| 192 | + "cell_type": "code", |
| 193 | + "execution_count": 123, |
| 194 | + "metadata": {}, |
| 195 | + "outputs": [ |
| 196 | + { |
| 197 | + "data": { |
| 198 | + "text/plain": [ |
| 199 | + "[('hearts', '7'), ('diamonds', '8'), ('clubs', '5')]" |
| 200 | + ] |
| 201 | + }, |
| 202 | + "execution_count": 123, |
| 203 | + "metadata": {}, |
| 204 | + "output_type": "execute_result" |
| 205 | + } |
| 206 | + ], |
| 207 | + "source": [ |
| 208 | + "board" |
| 209 | + ] |
| 210 | + }, |
| 211 | + { |
| 212 | + "cell_type": "code", |
| 213 | + "execution_count": 124, |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [ |
| 216 | + { |
| 217 | + "data": { |
| 218 | + "text/plain": [ |
| 219 | + "[('hearts', '7'),\n", |
| 220 | + " ('diamonds', '8'),\n", |
| 221 | + " ('clubs', '5'),\n", |
| 222 | + " ('hearts', '2'),\n", |
| 223 | + " ('clubs', '9')]" |
| 224 | + ] |
| 225 | + }, |
| 226 | + "execution_count": 124, |
| 227 | + "metadata": {}, |
| 228 | + "output_type": "execute_result" |
| 229 | + } |
| 230 | + ], |
| 231 | + "source": [ |
| 232 | + "deck2[4::5][0:5]" |
| 233 | + ] |
| 234 | + }, |
| 235 | + { |
| 236 | + "cell_type": "code", |
| 237 | + "execution_count": null, |
| 238 | + "metadata": { |
| 239 | + "collapsed": true |
| 240 | + }, |
| 241 | + "outputs": [], |
| 242 | + "source": [ |
| 243 | + "# made scores by probability\n" |
| 244 | + ] |
| 245 | + } |
| 246 | + ], |
| 247 | + "metadata": { |
| 248 | + "kernelspec": { |
| 249 | + "display_name": "Python 3", |
| 250 | + "language": "python", |
| 251 | + "name": "python3" |
| 252 | + }, |
| 253 | + "language_info": { |
| 254 | + "codemirror_mode": { |
| 255 | + "name": "ipython", |
| 256 | + "version": 3 |
| 257 | + }, |
| 258 | + "file_extension": ".py", |
| 259 | + "mimetype": "text/x-python", |
| 260 | + "name": "python", |
| 261 | + "nbconvert_exporter": "python", |
| 262 | + "pygments_lexer": "ipython3", |
| 263 | + "version": "3.5.4" |
| 264 | + } |
| 265 | + }, |
| 266 | + "nbformat": 4, |
| 267 | + "nbformat_minor": 2 |
| 268 | +} |
0 commit comments