Created
December 6, 2012 13:55
-
-
Save ptahdunbar/4224609 to your computer and use it in GitHub Desktop.
Get your Vac Team number!
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
/** | |
* Echos which VAC team you belong to. | |
* | |
* @params string $name Name of the person employed by VC Consulting. | |
* @return int Vac Team | |
*/ | |
function getVacTeamByName($name = '') | |
{ | |
$nameTotal = 0; | |
foreach ( str_split($name) as $char ) { | |
$nameTotal += ord($char); | |
} | |
$team = 0; | |
foreach ( str_split( $nameTotal ) as $teamTotal ) { | |
$team += $teamTotal; | |
} | |
return ( $team % 3 ); | |
} | |
$people = array( | |
'ptah', | |
'alain', | |
'antoine', | |
'christophe', | |
'emilien', | |
'frederic', | |
'gauthier', | |
'morgane', | |
'philippe', | |
'pascal', | |
'renaud', | |
'thibault', | |
'sandra', | |
'jeremy', | |
'eric', | |
); | |
$teams = array(); | |
foreach ( $people as $person ) { | |
$teams[$person] = getVacTeamByName($person); | |
} | |
asort($teams); | |
echo '<pre>'; | |
var_dump($teams); | |
/* | |
array(15) { | |
["renaud"]=> | |
int(0) | |
["ptah"]=> | |
int(0) | |
["thibault"]=> | |
int(0) | |
["sandra"]=> | |
int(0) | |
["antoine"]=> | |
int(0) | |
["jeremy"]=> | |
int(1) | |
["pascal"]=> | |
int(1) | |
["philippe"]=> | |
int(1) | |
["morgane"]=> | |
int(1) | |
["alain"]=> | |
int(1) | |
["christophe"]=> | |
int(1) | |
["emilien"]=> | |
int(1) | |
["eric"]=> | |
int(2) | |
["frederic"]=> | |
int(2) | |
["gauthier"]=> | |
int(2) | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment