Skip to content

Instantly share code, notes, and snippets.

@moolen
Last active March 7, 2017 16:44
Show Gist options
  • Save moolen/fd2709353ed7d09199c184f78c0a0b4a to your computer and use it in GitHub Desktop.
Save moolen/fd2709353ed7d09199c184f78c0a0b4a to your computer and use it in GitHub Desktop.
brute-force seed for fizzbuzz
<?php
for($i = PHP_INT_MIN; $i <= PHP_INT_MAX; $i++){
echo "$i".PHP_EOL;
srand($i);
if( magic() ){
echo "lucky number is #$i";
exit;
}
}
echo "no luck. yer' dead";
function magic(){
$yep = [0,0,1,0,2,1,0,0,1,2,0,1,0,0,3];
for($i=0; $i<15; $i++){
if( $yep[$i] !== rand(0,3) ){
return false;
}
}
return true;
}
<?php
$lucky = 1781773465;
$words = ['','fizz','buzz', 'fizzbuzz'];
for($i=1; $i<=100;$i++){
if( $i%15 == 1 ){
srand($lucky);
}
echo "$i: ".$words[rand(0,3)] . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment