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.
Running time[edit | edit source]
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.
Known bugs[edit | edit source]
Many users report that the algorithm tends to become locked when making the announcement, refusing to accept any input and instead just repeating "Please stand up, please stand up,..." A reported (but untested) fix for this is to turn up the bass, fool!. A much rarer bug has been dubbed the "megalomania remix", where the machine stops its search for the real Slim Shady and starts claiming that it is the real Slim Shady, and all other possible candidates are "just imitating".
History of the Slim Shady Algorithm[edit | edit source]
The first known reference to the Slim Shady Algorithm was its successful use by the Roman general Spartacus to identify the rebel Crassus. However, it was formally derived in 1914 by the renowned Serbian amateur mathematician Gavrilo Princip, with the assistance of Archduke Franz Ferdinand of Austria and a .32 caliber pistol. In 1993, the Slim Shady Algorithm was proved to have vital practical importance in the field of Nu-Math. In 1999 a song based on the algorithm was penned by rapper, homophobe, and lion-tamer Eminem. The song went on to see unheard-of success, becoming the only single in history to go infinity platinum. (In case you didn't already recognize this, infinity platinum is super cool.)
The Actual Algorithm's implementations[edit | edit source]
The following is a selection of actual implementations of the Algorithm, written by tediously funny people.
- In shady
'Cause I'm Slim Shady, yes I'm the real Shady All you other Slim Shadys are just imitating So won't the real Slim Shady please stand up, please stand up, please stand up?
- In Ada
with Ada.Text_Io ;
with ShadyMotions ;
Procedure SlimShady is
slim_shady : Boolean := FALSE ;
slim_shady_stood_up : Boolean := FALSE ;
Begin
While Not slim_shady Loop
Ada.Text_Io.Put_Line("Won't the Real Slim Shady please stand up.") ;
slim_shady_stood_up := ShadyMotions.SlimShadyStandsUp() ;
If(slim_shady_stood_up) then
slim_shady := TRUE ;
Ada.Text_Io.Put_Line("Slim Shady stood up.") ;
Ada.Text_Io.New_Line ;
End If ;
End Loop ;
Ada.Text_Io.Put_Line("kthx") ;
End SlimShady ;
- In C
#include <stdio.h>
#include "slimshady.h"
int main(int argc, char **argv)
{
int slim_shady = 0;
while (!slim_shady) {
printf("Won't the Real Slim Shady please stand up.\n");
if(slimshadystandsup()) slim_shady = 1;
}
printf("Slim Shady stood up!\n");
system("complain --life --everything-else");
return 0;
}
- In C++
#include <iostream>
#include "standup.h"
#include "slim.h"
int main(int argc, char **argv)
{
slim::shady slimshady;
while (!slimshady.real()) {
std::cout << "Will the real Slim Shady please stand up?\n";
standup::standupstream >> slimshady;
}
std::cout << "Slim Shady stood up\n";
return 0;
}
- In C#
using System;
using System.Text;
namespace RealSlimShady
{
class SlimShady
{
static void Main(string[] args)
{
string Sinput="";
while (true)
{
Console.WriteLine("Will the real Slim Shady please stand up? When Standing, press S");
Sinput = Console.ReadLine();
if (Sinput == "S")
{
Console.WriteLine("Standing: Thank You");
return;
}
}
}
}
}
- In Haskell
import Control.Monad.List
import Control.Monad.Trans
import Monad
import Shady
import IO
slimshady :: MonadIO m => m Shady
slimshady = do
people <- sittingPeople
result <- runListT $ do
liftIO $ putStrLn "Won't the Real Slim Shady please stand up."
shady <- msum $ map return people
guard $ isRealShady shady
please $ standUp shady
(isStanding shady) >>= guard
return shady
case result of
[] -> slimshady
[x] -> return x
_ -> error "Slim Shady has been cloned; panicking (you should, too)"
- In Pascal
Var RealStanding : Boolean;
Begin
While RealStanding = False
Do
Writeln('Would the real Slim Shady please stand up?');
End.
- In Java
import java.io.*;
import java.crowd;
public class SlimShady {
private static boolean m_slimshady = false;
public static void main(String[] args){
while(!m_slimshady){
System.out.println("Won't the real Slim Shady please stand up?");
try{
// NOTE crowd.getWhoStoodUp() may return null in case of no upstanding.
// By comparing from the static string we avoid the exception.
m_slimshady = "Slim Shady".equalsIgnoreCase(crowd.getWhoStoodUp());
Thread.sleep(1000);
} catch (Exception x) {
x.printStackTrace();
System.exit(10);
}
}
System.out.println("The real Slim Shady stood up");
}
}
- In Javascript
;( function( possiblyShady ) {
for ( var i = 0; i < possiblyShady.length; i += 1 ) {
if ( ! possiblyShady[ i ].isShady ) {
console.log( "Will the real slim shady please stand up?" );
}
else {
console.log( possiblyShady[ i ].name + " is the real slim shady." );
return;
}
}
console.log( "There is no real slim shady." );
})( window.possiblyShady );
- In Python
def slim_shady(shadylist):
# slim_shady takes a list of Slim Shadies, returns Real Slim Shady, if exists
for shady in shadylist:
print "Won't the real Slim Shady please stand up?"
if shady == "Slim Shady":
# it's safe to return here, because it's clear that any remaining
# shadies in this sequence are just imitating
return shady
return None
- In Lisp
(defun real-thlim-shady (shadys)
(if (equal (car shadys) "The Real Thlim Shady")
(format t "The real Thlim Shady hath thtood up.")
(real-thlim-shady (cdr shadys))))
- In Scheme
(define (slimshady slim-shadys)
(if (null? slim-shadys)
'()
(if (real? (car slim-shadys))
(car slim-shadys)
(slimshady (cdr slim-shadys)))))
- In MATLAB
disp('Will the real Slim Shady please stand up?')
stood_up = find(isshady(crowd));
switch length(stood_up)
case 1
disp('The real Slim Shady stood up.')
realSlimShady = crowd(stood_up);
case 0
disp('Shady was eaten by zombies.')
realSlimShady = [];
otherwise
disp('Shady clones?!')
realSlimShady = crowd(stood_up(1));
feed2zombies(crowd(stood_up(2:end)));
end
- In mIRCscript
alias slimshady { /set %realslimshady $read(slimshady.def) if (%realslimshady != 1) { /echo -t Would the real Slim Shady please stand up? | /halt } /echo -t The real Slim Shady stood up. }
- In PHP
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. Then what he said about there being a shady in all of us is true.", E_USER_ERROR);
}
else {
exit("ICE ICE BABY!");
}
}
}
- In QBASIC
5 ON ERROR RESUME NEXT
10 PRINT "Won't the real Slim Shady Please Stand up?"
15 PRINT "(otherwise please press <CTRL><C> to cancel)"
20 IF STANDING<>TRUE THEN GOTO 10 ELSE GOTO 30
30 PRINT "WOOT!"
40 END
- In Visual Basic
Do while slimshadystanding.value = 0
If slimshadystandsup = 1 then
Print "Slim Shady stood up!"
slimshadystanding.value = 1 else
Endwhile
- In Ruby
def slim_shady_finder homies
puts "Won't the real Slim Shady please stand up?"
homies.find{ |some_guy| some_guy.name == 'Slim Shady'}
end
- In Developers
Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers DevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers DevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers DevelopersDevelopersDevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers\ DevelopersDevelopersDevelopersDevelopersDevelopersDevelopersDevelopersDevelopersDevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers DevelopersDevelopersDevelopersDevelopersDevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers DevelopersDevelopers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers Developers
- In Brainfuck
+++++++++++++++++++++++++++++++++>>++++++++++[>+++++++++>+++++++++++>+++++++++++>++++++++++++ >+++>++++++++++++>++++++++++>++++++++++>+++>++++++++>++++++++++>++++++++++>+++++++++++>+++>++ ++++++>+++++++++++>+++++++++++>+++++++++++>+++>++++++++>++++++++++>++++++++++>++++++++++>++++ ++++++++>+++>+++++++++++>+++++++++++>++++++++++>++++++++++>++++++++++++>++++++++++>+++>++++++ ++++++>++++++++++++>++++++++++>+++++++++++>++++++++++>+++>++++++++++++>+++++++++++>+++++><<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-]>--->+>>---->++>---->++++>+>++>++>+>--->-->++>+++>--> ----->->++>+++>++++>--->>+>++>++>-->+>--->----->+>++>----->---->--->>>++>--->++>----><<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> .>.>.>.>.>.>.>.>.>.>.>.>.>.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-]
- In AAAAAAAAA!
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAA!!! AA! A!
- In SQL
SELECT * FROM SLIM_SHADIES_TBL WHERE REAL<>NULL;
- In LifeScript
{function .title "herpes.lsf" :ask =won't the real slim shady please stand up? -accent _english _american .sk?" &function=ask+girl endfunction} _run "herpes.lsf"
- In Perl
use SlimShady qw($real_shady);
open (my $SHADIES, '<', 'shadylist') or die "Ain't no Shadies here: $!";
while (<$SHADIES>) {
chomp;
print "Won't the real Slim Shady please stand up?\n";
print "The real Shady stood up!\n\n" if /$real_shady/;
}
- In Whitespace