Last active
January 11, 2021 23:29
-
-
Save danielpcox/daab61589803911738d0431c295205aa to your computer and use it in GitHub Desktop.
A pair programming rotation for five people
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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Pairing Rotation" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"How to get all pairings from a list?\n", | |
"\n", | |
"It's important that no two pairings be repeated, and that everyone be paired with everyone else." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from itertools import permutations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"people = ['Daniel', 'Hiromi', 'Andrew', 'Peter', 'Patrick'] #, 'Nobody']" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"perms = list(permutations(people))\n", | |
"# perms" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"n = 2\n", | |
"idxs = [i for i in range(0,len(people),n)]\n", | |
"# idxs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pairings = [ tuple(sorted([tuple(sorted(p[i:i+n])) for i in idxs])) for p in perms]\n", | |
"# pairings" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"120" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(pairings)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"unique_pairings = set(pairings)\n", | |
"# unique_pairings" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"15" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(unique_pairings)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[[('Andrew', 'Patrick'), ('Daniel', 'Peter'), ('Hiromi',)],\n", | |
" [('Andrew', 'Daniel'), ('Patrick', 'Peter'), ('Hiromi',)],\n", | |
" [('Andrew', 'Patrick'), ('Daniel', 'Hiromi'), ('Peter',)],\n", | |
" [('Andrew', 'Daniel'), ('Hiromi', 'Peter'), ('Patrick',)],\n", | |
" [('Andrew', 'Hiromi'), ('Daniel', 'Patrick'), ('Peter',)],\n", | |
" [('Daniel', 'Peter'), ('Hiromi', 'Patrick'), ('Andrew',)],\n", | |
" [('Andrew', 'Peter'), ('Hiromi', 'Patrick'), ('Daniel',)],\n", | |
" [('Andrew', 'Hiromi'), ('Patrick', 'Peter'), ('Daniel',)],\n", | |
" [('Daniel', 'Hiromi'), ('Patrick', 'Peter'), ('Andrew',)],\n", | |
" [('Daniel', 'Patrick'), ('Hiromi', 'Peter'), ('Andrew',)],\n", | |
" [('Andrew', 'Patrick'), ('Hiromi', 'Peter'), ('Daniel',)],\n", | |
" [('Andrew', 'Peter'), ('Daniel', 'Patrick'), ('Hiromi',)],\n", | |
" [('Andrew', 'Hiromi'), ('Daniel', 'Peter'), ('Patrick',)],\n", | |
" [('Andrew', 'Peter'), ('Daniel', 'Hiromi'), ('Patrick',)],\n", | |
" [('Andrew', 'Daniel'), ('Hiromi', 'Patrick'), ('Peter',)]]" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"[sorted(pairing,reverse=True,key=lambda s:len(s)) for pairing in unique_pairings]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"hide_input": false, | |
"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.8.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment