The Slim Shady Algorithm
The Uncyclopedia has its moments. Consider the hilarious Slim Shady Algorithm:
When faced with a large group of similar looking people, the Slim-Shady Algorithm can be applied to deduce which member of the group is the authentic person whom you are seeking.
The algorithm is applied by simply announcing “Won’t the real X please stand up” over and over again (where X denotes the name of the person you are seeking) until the real person stands up.
… The algorithm runs in O(N) time, which makes it a linear-running algorithm. A more complex version can achieve O(log N) efficiency, but this requires the use of a tree. Note that there is an overhead cost associated with cutting down the tree to get the log.
An implementation is given in PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | require_once('libshady.php'); global $shadies; $standing_up = 0; $real_slim_shady = false; foreach ($shadies as $shady) { if (!$standing_up) { echo "<marquee><blink><big><big><big>Won't the real Slim Shady please stand up?</big></big></big></blink></marquee>"; $real_slim_shady = assess_shadiness($shady); if ($real_slim_shady){ $standing_up++; } } else { if ($standing_up > 1) { trigger_error("Multiple shadies found. This can't be right", E_USER_ERROR); } else { exit("ICE ICE BABY!"); } } } |