Skip to content

Instantly share code, notes, and snippets.

@remydagostino
Created October 26, 2020 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remydagostino/0b0a98f4f98741fde9bd6dcb1b48aac6 to your computer and use it in GitHub Desktop.
Save remydagostino/0b0a98f4f98741fde9bd6dcb1b48aac6 to your computer and use it in GitHub Desktop.
Social Beverage Programme
// Usage: node matcher.js people-list.txt 2
const people = require('fs').readFileSync(process.argv[2]).toString().split('\n');
const weekNum = Number(process.argv[3]);
const pairs = people
.map((person, index) => people[(index + weekNum) % people.length])
.map((person, index, list) => {
const match = list[list.length - index - 1];
if (match === person) {
return [person, list[0]];
} else {
return [person, match];
}
})
.map(pair => weekNum % 2 ? pair.reverse() : pair)
.slice(0, Math.floor((people.length + 1) / 2));
console.log(pairs.map(pair => pair.join(' -> ')).join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment