- https://www.codewars.com/kata/585d7d5adb20cf33cb000235 Find the unique number
Started at 23:41 14.11.2020 Saturday.
Finished at 01:13 15.11.2020 Sunday.
<?php | |
# https://www.codewars.com/kata/585d7d5adb20cf33cb000235 Find the unique number. | |
function find_uniq($a) { | |
$a_ = $a[0]; $b_ = $a[1]; $c_ = $a[2]; | |
if($a_ != $b_ && $a_ != $c_) return $a_; | |
if($b_ != $a_ && $b_ != $c_) return $b_; | |
if($c_ != $a_ && $c_ != $b_) return $c_; | |
$not = $a_; | |
$size = count($a); | |
for($i = 3; $i < $size; $i++) | |
if($not != $a[$i]) return $a[$i]; | |
throw new Exception('No answer.'); | |
} |
Started at 23:41 14.11.2020 Saturday.
Finished at 01:13 15.11.2020 Sunday.