- https://www.codewars.com/kata/5526fc09a1bbd946250002dc Find The Parity Outlier.
Started at 19:47 16.10.2020 Friday Oct.
Finished at 20:04 16.10.2020 Friday Oct. (0hrs 17minutes)
<?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.'); | |
} |
Started at 19:47 16.10.2020 Friday Oct.
Finished at 20:04 16.10.2020 Friday Oct. (0hrs 17minutes)