Skip to content

Instantly share code, notes, and snippets.

@opengeek
Created July 31, 2012 13:58
Show Gist options
  • Save opengeek/3217234 to your computer and use it in GitHub Desktop.
Save opengeek/3217234 to your computer and use it in GitHub Desktop.
<?php
$m = mt_rand(1, 100);
$list = range(1, 100);
unset($list[array_search($m, $list)]);
function missing(array $list) {
$n = count($list);
$allSum = ($n+1)*($n+2)/2;
return $allSum - array_sum($list);
}
echo missing($list) . "\n";
echo $m . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment