Skip to content

Instantly share code, notes, and snippets.

@jaredririe
Last active September 30, 2021 17:26
Show Gist options
  • Select an option

  • Save jaredririe/7b76eb51e07f05d983cf147b388a5694 to your computer and use it in GitHub Desktop.

Select an option

Save jaredririe/7b76eb51e07f05d983cf147b388a5694 to your computer and use it in GitHub Desktop.
Cousin Gift Exchange (ensures that gifts are only given to cousins, not siblings)
const _ = require('lodash');
const families = [
[
{ name: "Corbyn", giftFrom: "" },
{ name: "Peyton", giftFrom: "" },
{ name: "Logan", giftFrom: "" },
{ name: "Easton", giftFrom: "" }
],
[
{ name: "Blake", giftFrom: "" },
{ name: "Skyler", giftFrom: "" },
{ name: "Grey", giftFrom: "" },
{ name: "Axel", giftFrom: "" }
],
[
{ name: "Madison", giftFrom: "" },
{ name: "Linnea", giftFrom: "" }
]
];
_.forEach(families, (family, i) => {
_.forEach(family, (member) => {
const otherFamilies = _.filter(families, (_, idx) => {
return idx != i;
})
while (true) {
const anotherFamily = _.sample(otherFamilies);
const randomCousin = _.sample(anotherFamily);
if (randomCousin.giftFrom == "") {
console.log(`${member.name} giving to ${randomCousin.name}`);
randomCousin.giftFrom = member.name;
break;
}
}
})
})
@jaredririe
Copy link
Copy Markdown
Author

Output 2018

Corbyn giving to Madison
Peyton giving to Skyler
Logan giving to Grey
Blake giving to Corbyn
Skyler giving to Logan
Grey giving to Peyton
Madison giving to Blake

@jaredririe
Copy link
Copy Markdown
Author

jaredririe commented Oct 7, 2019

Output 2019

Corbyn giving to Grey
Peyton giving to HobbsBaby
Logan giving to Madison
Easton giving to Blake

Blake giving to Easton
Skyler giving to Corbyn
Grey giving to Linnea
HobbsBaby giving to Peyton

Madison giving to Skyler
Linnea giving to Logan

@jaredririe
Copy link
Copy Markdown
Author

Output 2020

Corbyn giving to Linnea
Peyton giving to Grey
Logan giving to Skyler
Easton giving to Axel

Blake giving to Easton
Skyler giving to Peyton
Grey giving to Logan
Axel giving to Madison

Madison giving to Blake
Linnea giving to Corbyn

@jaredririe
Copy link
Copy Markdown
Author

Output 2020

Jared giving to Timothy
Cailey giving to Matt
Timothy giving to Elise
Claudia giving to Jared
Matt giving to Cailey
Elise giving to Claudia

@jaredririe
Copy link
Copy Markdown
Author

jaredririe commented Sep 30, 2021

Output 2021

Corbyn giving to Grey
Peyton giving to Blake
Logan giving to Linnea
Easton giving to Axel

Blake giving to Madison
Skyler giving to Logan
Grey giving to Easton
Axel giving to Corbyn

Madison giving to Peyton
Linnea giving to Skyler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment