Last active
February 14, 2022 13:16
-
-
Save mjoyce91/41d7b5304c8570d3a9f785322b63a772 to your computer and use it in GitHub Desktop.
Super Bowl Squares Generator
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
// Step 1. Go to lodash.com | |
// Step 2. Press F12 to open Developer Tools | |
// Step 3. Go to the "Console" tab | |
// Step 4. Copy and paste this entire gist into the console | |
// Step 5. Replace the value of "persons" with your list of participants | |
// Step 6. Press enter. A table will appear with Bengals scores going across, Rams scores going down. | |
// Note: If participants cannot be evenly distributed into all 100 squares, generated picks will be "pushed" to the left | |
// and you will end up with some empty squares. | |
const create = () => { | |
const persons = ['Mom', 'Bill', 'Mary', 'Dad', 'Grandma'] | |
const bengals = [0,1,2,3,4,5,6,7,8,9] | |
const rams = [0,1,2,3,4,5,6,7,8,9] | |
const picks = []; | |
const choose = (person) => { | |
const name = person; | |
const picksCount = Math.floor(100 / persons.length); | |
const pick = () => { | |
const b = _.sample(bengals); | |
const r = _.sample(rams); | |
const pick$ = b + ',' + r; | |
const found = picks.find(f => f[0] === pick$); | |
if (found) { | |
pick(); | |
} else { | |
picks.push([pick$, `Bengals: ${b}, Rams: ${r}`, name, { bengals: b, rams: r }]); | |
} | |
} | |
Array.from(Array(picksCount).keys()).forEach(f => pick()) | |
} | |
persons.forEach(p => choose(p)) | |
console.log('Bengals across, Rams down') | |
console.table( | |
// this will "push" picks to the left if the participants cannot be evenly distributed into 100 | |
bengals.map(b => _.sortBy(picks.filter(a => a[3].rams === b), f => f[3].bengals).map(m => m[2]) ), | |
); | |
} | |
create(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment