- Open a terminal and
paste
the following command ☝️😲WITHOUT EXECUTING IT:
pbpaste | npx https://gist.github.com/abernier/00ac26ff978aebdfa6f3f65019fe2bf0 10 | pbcopy
NB:10
being the number of combinations wanted - In a spreadsheet,
copy
rows of names: - In the previous terminal, press now
ENTER
to execute the pasted command at step0.
:
Paste
the result into spreadsheet
Last active
September 9, 2019 11:46
-
-
Save abernier/00ac26ff978aebdfa6f3f65019fe2bf0 to your computer and use it in GitHub Desktop.
ironpairs
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
#!/usr/bin/env node | |
// Run | |
// --- | |
// $ npm install roundrobin | |
// $ pbpaste | node pairs.js 25 | pbcopy | |
const roundrobin = require('roundrobin') | |
const numberOfRounds = Number(process.argv[2]) | |
let names = process.argv.slice(3) | |
if (names.length > 0) { | |
assignPairs(names) | |
} else { | |
let nameString = '' | |
process.stdin.setEncoding('utf8') | |
process.stdin.on('data', chunk => nameString += chunk) | |
process.stdin.on('end', () => { | |
names = nameString.split('\n') | |
assignPairs(names) | |
}) | |
} | |
function assignPairs (namesArray) { | |
// Add an extra name for odd numbered groups. | |
// Otherwise roundrobin leaves out the extra name in each round. | |
if (namesArray.length % 2 === 1) { | |
namesArray.push('Imaginary Pair') | |
} | |
let pairs = [] | |
// Create several sets of pairs to fill all pairing days needed. | |
// We will get some extras but they can be useful. | |
while (pairs.length < numberOfRounds) { | |
const newPairs = roundrobin(namesArray.length, namesArray) | |
pairs = pairs.concat(newPairs) | |
} | |
// If odd numbered group, assign trios in each round. | |
if (namesArray.indexOf('Imaginary Pair') > -1) { | |
const trioCount = {} | |
const triodPairs = [] | |
namesArray.forEach(name => trioCount[name] = 0) | |
pairs.forEach(round => { | |
let extraName | |
// Get rid of the 'Imaginary Pair' pairing | |
const roundWithTrio = round | |
.filter(pair => { | |
const extraIndex = pair.indexOf('Imaginary Pair') | |
// Keep extra name that was paired with 'Imaginary Pair' this round | |
if (extraIndex > -1) { | |
const nameIndex = (extraIndex + 1) % 2 | |
extraName = pair[nameIndex] | |
} | |
return extraIndex === -1 | |
}) | |
.sort((pairA, pairB) => { | |
const trioCountA = trioCount[pairA[0]] + trioCount[pairA[1]] | |
const trioCountB = trioCount[pairB[0]] + trioCount[pairB[1]] | |
return trioCountA - trioCountB | |
}) | |
let currentTrio = roundWithTrio[0] | |
currentTrio.push(extraName) | |
currentTrio.forEach(name => trioCount[name] += 1) | |
// Save new round | |
triodPairs.push(roundWithTrio) | |
}) | |
pairs = triodPairs | |
} | |
// Display results for pasting onto spreadsheet. | |
let row = '' | |
pairs.forEach(function (round) { | |
row += '"' | |
round.forEach(function (pairing) { | |
row += `${pairing[0]} with ${pairing[1]}` | |
if (pairing.length > 2) { | |
row += ` and ${pairing[2]}` | |
} | |
row += '\n' | |
}) | |
row += '"\t' | |
}) | |
console.log(row) | |
} |
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
{"name": "ironpairs", "version": "0.1.0", "bin": "./index.js", "dependencies": {"roundrobin": "1.0.3"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment