Created
October 31, 2014 10:23
-
-
Save damienalexandre/9483de44cf1219a74973 to your computer and use it in GitHub Desktop.
Secret Santa matcher with PHP Generator
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]", | |
]; | |
function giveMeABuddy($players) { | |
// Make sure results are not predictable | |
shuffle($players); | |
$players = array_values($players); | |
foreach ($players as $key => $player) { | |
$santa = $players[(count($players)-1) - $key]; | |
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
https://gist.github.com/paulmallet/3221afc9ccf0ccbbfb85