|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 3, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {
|
7 |
| - "collapsed": true |
| 7 | + "collapsed": false |
8 | 8 | },
|
9 | 9 | "outputs": [],
|
10 | 10 | "source": [
|
11 | 11 | "import numpy as np\n",
|
12 | 12 | "\n",
|
13 |
| - "classmates = ['Alexander','Bryan','Cindy','Crystal','DanielG','DanielT','Eric','Everett','Harry','John','Justin','Miles','Monika','Srikanth','Swathi','Tetyana','Timothy','Yeongcheon']\n", |
14 |
| - "\n", |
15 |
| - "def pairs(classmates, day=1):\n", |
16 |
| - " classmates.sort()\n", |
17 |
| - " if day > 4:\n", |
18 |
| - " day += 1\n", |
19 |
| - " for ind, value in enumerate(classmates):\n", |
20 |
| - " if ind%2==False and day*2 <= len(classmates):\n", |
21 |
| - " print value + ' *PAIR* ' + classmates[(ind-1+day*2)%len(classmates)]\n", |
22 |
| - " elif ind*2 < len(classmates) and day*2 > len(classmates) and day-10%len(classmates)!=(ind+day%10)%len(classmates): \n", |
23 |
| - " print classmates[(ind+day%10)%len(classmates)] + ' *PAIR* ' + classmates[(len(classmates)-ind+day%10)%len(classmates)]\n", |
24 |
| - " elif day-10%len(classmates)==(ind+day%10)%len(classmates):\n", |
25 |
| - " print classmates[(ind+day%10)%len(classmates)] + ' *PAIR* ' + classmates[(ind+9+day%10)%len(classmates)] " |
26 |
| - ] |
27 |
| - }, |
28 |
| - { |
29 |
| - "cell_type": "code", |
30 |
| - "execution_count": 56, |
31 |
| - "metadata": { |
32 |
| - "collapsed": false |
33 |
| - }, |
34 |
| - "outputs": [ |
35 |
| - { |
36 |
| - "name": "stdout", |
37 |
| - "output_type": "stream", |
38 |
| - "text": [ |
39 |
| - "Harry *PAIR* Yeongcheon\n", |
40 |
| - "John *PAIR* Everett\n", |
41 |
| - "Justin *PAIR* Eric\n", |
42 |
| - "Miles *PAIR* Daniel T\n", |
43 |
| - "Monika *PAIR* Daniel G\n", |
44 |
| - "Srikanth *PAIR* Crystal\n", |
45 |
| - "Swathi *PAIR* Cindy\n", |
46 |
| - "Tetyana *PAIR* Bryan\n", |
47 |
| - "Timothy *PAIR* Alexander\n" |
48 |
| - ] |
49 |
| - } |
50 |
| - ], |
51 |
| - "source": [ |
52 |
| - "pairs(classmates, 17)" |
53 |
| - ] |
54 |
| - }, |
55 |
| - { |
56 |
| - "cell_type": "code", |
57 |
| - "execution_count": 58, |
58 |
| - "metadata": { |
59 |
| - "collapsed": false |
60 |
| - }, |
61 |
| - "outputs": [], |
62 |
| - "source": [ |
63 |
| - "def cpairs(classmates, day):\n", |
| 13 | + "def pairs(classmates, day):\n", |
64 | 14 | " classmates.sort()\n",
|
65 | 15 | " n = len(classmates)\n",
|
66 |
| - " mask = np.ones(n, dtype=bool) # initiate a mask to indicate who has or has not been paired\n", |
| 16 | + " paired = np.ones(n, dtype=bool) # initiate a mask to indicate who has or has not been paired\n", |
67 | 17 | " day = (day-1)%(n-1) # start day count from 0 and repeat pairings if day > (n-1)\n",
|
68 | 18 | " \n",
|
69 | 19 | " if day <= n/2:\n",
|
70 | 20 | " day += day/(n/4) # skip the day when people pair across\n",
|
71 | 21 | " for i in xrange(n):\n",
|
72 |
| - " if mask[i]:\n", |
| 22 | + " if paired[i]:\n", |
73 | 23 | " if i%2 == 0:\n",
|
74 | 24 | " print classmates[i] + ', ' + classmates[(i+1+day*2)%n]\n",
|
75 |
| - " mask[i], mask[(i+1+day*2)%n] = 0, 0\n", |
| 25 | + " paired[i], paired[(i+1+day*2)%n] = 0, 0\n", |
76 | 26 | " else:\n",
|
77 | 27 | " print classmates[i] + ', ' + classmates[(i-1-day*2)%n]\n",
|
78 |
| - " mask[i], mask[(i-1-day*2)%n] = 0, 0\n", |
| 28 | + " paired[i], paired[(i-1-day*2)%n] = 0, 0\n", |
79 | 29 | " \n",
|
80 |
| - " elif day >= n/2:\n", |
| 30 | + " elif day > n/2:\n", |
81 | 31 | " head = day - n/2 +1 # marks the person pairing across\n",
|
82 | 32 | " for i in xrange(n):\n",
|
83 |
| - " if mask[i]:\n", |
| 33 | + " if paired[i]:\n", |
84 | 34 | " if i == head:\n",
|
85 | 35 | " print classmates[head] + ', ' + classmates[head+(n/2)]\n",
|
86 |
| - " mask[head], mask[head+(n/2)] = 0, 0\n", |
| 36 | + " paired[head], paired[head+(n/2)] = 0, 0\n", |
87 | 37 | " else:\n",
|
88 | 38 | " print classmates[i] + ', ' + classmates[(2*head+n-i)%n]\n",
|
89 |
| - " mask[i], mask[(2*head+n-i)%n] = 0, 0\n" |
| 39 | + " paired[i], paired[(2*head+n-i)%n] = 0, 0\n" |
90 | 40 | ]
|
91 | 41 | },
|
92 | 42 | {
|
93 | 43 | "cell_type": "code",
|
94 |
| - "execution_count": 13, |
| 44 | + "execution_count": 2, |
95 | 45 | "metadata": {
|
96 | 46 | "collapsed": true
|
97 | 47 | },
|
98 | 48 | "outputs": [],
|
99 | 49 | "source": [
|
100 |
| - "classmates = ['Alexander','Bryan','Cindy','Crystal','Daniel G','Daniel T','Eric','Everett','Harry','John','Justin','Miles','Monika','Srikanth','Swathi','Tetyana','Timothy','Yeongcheon']\n" |
| 50 | + "classmates = ['Alexander','Bryan','Cindy','Crystal','Daniel G','Daniel T','Eric','Everett','Harry','John',\n", |
| 51 | + " 'Justin','Miles','Monika','Srikanth','Swathi','Tetyana','Timothy','Yeongcheon']\n" |
101 | 52 | ]
|
102 | 53 | },
|
103 | 54 | {
|
|
124 | 75 | }
|
125 | 76 | ],
|
126 | 77 | "source": [
|
127 |
| - "cpairs(classmates, 3)" |
| 78 | + "pairs(classmates, 3)" |
128 | 79 | ]
|
129 | 80 | },
|
130 | 81 | {
|
|
183 | 134 | },
|
184 | 135 | {
|
185 | 136 | "cell_type": "code",
|
186 |
| - "execution_count": 60, |
| 137 | + "execution_count": 3, |
187 | 138 | "metadata": {
|
188 | 139 | "collapsed": false
|
189 | 140 | },
|
|
205 | 156 | }
|
206 | 157 | ],
|
207 | 158 | "source": [
|
208 |
| - "cpairs(classmates, 19)" |
209 |
| - ] |
210 |
| - }, |
211 |
| - { |
212 |
| - "cell_type": "code", |
213 |
| - "execution_count": null, |
214 |
| - "metadata": { |
215 |
| - "collapsed": false |
216 |
| - }, |
217 |
| - "outputs": [], |
218 |
| - "source": [] |
219 |
| - }, |
220 |
| - { |
221 |
| - "cell_type": "code", |
222 |
| - "execution_count": null, |
223 |
| - "metadata": { |
224 |
| - "collapsed": true |
225 |
| - }, |
226 |
| - "outputs": [], |
227 |
| - "source": [ |
228 |
| - " elif day > n/4 and day < n/2:\n", |
229 |
| - " for i in xrange(n):\n", |
230 |
| - " if mask[i]:\n", |
231 |
| - " if i%2 == 0:\n", |
232 |
| - " print classmates[i] + ', ' + classmates[(i+1+day*2)%n]\n", |
233 |
| - " mask[i], mask[(i-1+day*2)%n] = 0, 0\n", |
234 |
| - " else:\n", |
235 |
| - " print classmates[i] + ', ' + classmates[(i-1-day*2)%n]\n", |
236 |
| - " mask[i], mask[(i+1-day*2)%n] = 0, 0" |
| 159 | + "cpairs(classmates, 2)" |
237 | 160 | ]
|
238 | 161 | }
|
239 | 162 | ],
|
|
253 | 176 | "name": "python",
|
254 | 177 | "nbconvert_exporter": "python",
|
255 | 178 | "pygments_lexer": "ipython2",
|
256 |
| - "version": "2.7.10" |
| 179 | + "version": "2.7.11" |
257 | 180 | }
|
258 | 181 | },
|
259 | 182 | "nbformat": 4,
|
|
0 commit comments