-
-
Save paulmallet/3221afc9ccf0ccbbfb85 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Secret Santa Generator - powered by PHP Generators for the lolz. | |
*/ | |
$players = [ | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
]; | |
function giveMeABuddy($players) { | |
// Make sure results are not predictable | |
shuffle($players); | |
foreach ($players as $key => $player) { | |
// each player is the buddy of the last one | |
$santa = $players[($key+1) % count($players)]; | |
yield $player => $santa; | |
} | |
} | |
foreach (giveMeABuddy($players) as $player => $santa) | |
{ | |
printf("%s is the santa of %s\n", $santa, $player); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment