Find the missing term in an Arithmetic Progression
An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.
You have to write the function findMissing(list), list will always be at least 3 numbers. The missing term will never be the first or last one.
function findMissing($list) {
$realSum = array_sum($list);
$should = ($list[0] + $list[count($list)-1]) * (count($list)+1) / 2;
return $should - $realSum;
}