Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Created October 16, 2020 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/b3f214c8e6e9d3a386dcedfde46073ec to your computer and use it in GitHub Desktop.
Save lbvf50mobile/b3f214c8e6e9d3a386dcedfde46073ec to your computer and use it in GitHub Desktop.
Just PHP FUN 130.
<?php
# https://www.codewars.com/kata/5526fc09a1bbd946250002dc Find The Parity Outlier.
function find($integers) {
$array_of_evens = arr_even($integers);
if($array_of_evens) return find_odd($integers);
return find_even($integers);
}
function arr_even(&$a){
$counter = 0;
for($i = 0; $i < 3; $i+=1)
if( 0 == $a[$i]%2) $counter += 1;
return $counter > 1;
}
function find_odd(&$a){
foreach($a as $val)
if(1 == ($val&1) ) return $val;
throw new Exception('Really, cannot find Odd value.');
}
function find_even(&$a){
foreach($a as $val) if(0 == ($val&1)) return $val;
throw new Exception('Really, cannot find Even value.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment