Algoritmo de la amistad

12 03 2010

Tras verme las temporadas 1 y 2 de The Big Bang Theory en poco más que una semana, no era de esperarse menos que esto.

Googleando un poco (por fiaca, más que nada), llegué a este blog en que está subido el diagrama de flujo del algoritmo de la amistad que descubrió Sheldon en un capítulo.

Diagrama de flujo del Algoritmo de la amistad de Sheldon Cooper

Algoritmo de la amistad, por Sheldon Cooper

Pues bien, nerdeando un poco, acá está la implementacióncasi textual de ese algoritmo en algo que espero que sea C:
/***************************************
* FriendShip Algorithm v1.0
* Copyrigth 2009 Sheldon Cooper
*
***************************************/
#include <friendship.h>
Friend makeFriend(){
    PlacePhoneCall();
    if(!home()){
        leaveMessage();
        waitForCallback();
    }
    if(wouldYouLikeToShareAMeal()){
        if(dineTogether()){
            return new Friend();
        }
    }else{
        if((beverage=doYouEnojoyAHotBeverage()) != NULL){
            switch(beverage){
                case 'tea':
                    haveTea();
                    break;
                case 'coffee':
                    haveCoffee();
                    break;
                case 'cocoa':
                    haveCocoa();
            }
            return new Friend();
        }else{
            do{
                interest = tellMeOneOfYourInterests();
            }while (!doIShareInterestIn(interest));
            whyDontWeDoTogether(interest);
            partakeIn(interest);
            return new Friend();
        }
    }
}

Y, un poco más ‘correctamente programada’:
/***************************************
* FriendShip Algorithm v1.0
* Copyrigth 2009 Sheldon Cooper
*
***************************************/
#include <humanity.h>
#include <friendship.h>
#include <telephone.h>
#include <eating.h>
Friend makeFriend(Person person){
    Call call = placePhoneCall(person);
    if(!atHome(person)){
        leaveMessage(call);
        waitForCallback(person);
    }
    if(wouldYouLikeToShareAMeal(person)){
        if(dineTogether(person)){
            return new Friend(person);
        }
    }else{
        if((Beverage beverage=doYouEnojoyAHotBeverage(person)) != NULL){
            switch(beverage){
                case 'tea':
                    haveTeaWith(person);
                    break;
                case 'coffee':
                    haveCoffeeWith(person);
                    break;
                case 'cocoa':
                    haveCocoaWith(person);
            }
            return new Friend(person);
        }else{
            do{
                Interest interest = tellMeOneOfYourInterests(person);
            }while (!doIShareInterestIn(interest));
            whyDontWeDoTogether(interest);
            partakeIn(interest);
            return new Friend(person);
        }
    }
    return NULL;
}

Realmente me llevo mejor con PHP que con C, pero juraría que sería algo muy similar a esto…


Acciones

Información

3 respuestas

12 03 2010
droope

jjajaa :D

estabas aburrido?? :P

12 03 2010
desert69

Mmm… ‘inspirado’, más bien :)

12 03 2010
Chone

JAJAJAJAJAJAA nunca lo habia visto asi, es genial

Es demasiado freak, demasiado bueno. Las librerias que carga el segundo xD

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s




Seguir

Get every new post delivered to your Inbox.