Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active November 14, 2020 18:13
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/756a7a409f133fbfb949b8b4b88c9e41 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/756a7a409f133fbfb949b8b4b88c9e41 to your computer and use it in GitHub Desktop.
Just PHP FUN 151.
<?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.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment