The Friendship Algorithm

The Friendship Algorithm

Postby metulburr » Sat May 03, 2014 5:31 am

New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: The Friendship Algorithm

Postby XndrK » Fri May 09, 2014 12:11 am

I (of course) implemented the Algorithm in Python.

Disclaimer: I HAVE NOT TESTED THIS. I just shoved it together in fifteen minutes of creative frenzy.
Also, I am not familiar with the show, so if there are any discrepancies I missed, feel absolutely free to fix the code.

Now, the Algorithm!

Code: Select all
from __future__ import *
import time

# some boilerplate classes
class FriendWannabe:
    """Base person class. Whoever runs the algorithm is a Person."""
    def __init__(self, interests):
        self.interests = interests # list with at least six items

class PotentialFriend(FriendWannabe):
    """Special case for the person who the person running the algorithm
        wants to be friends with.

        Inherits from FriendWannabe for simplicity's sake."""
    def __init__(self, home, wants_a_beverage, favorite_beverage, wants_to_dine, interests):
        super(Person, self).__init__(interests)
        self.home = home # bool
        self.favorite_beverage = favorite_beverage # string
        self.wants_to_dine = wants_to_dine

    def call_back():
        print("Hello?")

# some boilerplate functions

def dine_together():
    print("Isn't this food delicious?")

def have_beverage(beverage):
    list_of_beverages = ["tea", "coffee", "cocoa"]
    while beverage not in list_of_beverages:
        raise StandardError("Hot beverage not in algorithm")
    else:
        time.sleep(5)
        print("Here's your {}".format(beverage))

def partake_in_interest(interest):
    print(interest + " sure is fun!")

def place_phone_call(recipient):
    for i in range(3):
        print("Ring!")
        time.sleep(1)
    if recipient.home:
        print("Hello?")

def begin_friendship():
    print("Friends!")

# let's roll!
def the_algorithm(friend_wannabe, potential_friend):
    """The Friendship Algorithm."""
    place_phone_call(potential_friend)
    if not potential_friend.home:
        time.sleep(5)
        potential_friend.call_back()
    # else
    print("Would you like to share a meal?")
    if potential_friend.wants_to_dine:
        dine_together()
        begin_friendship()
        return
    # else
    print("Do you enjoy a hot beverage?")
    if potential_friend.wants_a_beverage:
        have_beverage(potential_friend.favorite_beverage)
        begin_friendship()
        return
    # else
    print("Tell me one of your interests.")
    for index, i in enumerate(potential_friend.interests):
        if i in friend_wannabe.interests:
            print("Why don't we do that together?")
            partake_in_interest(i)
            begin_friendship()
            return
        else:
            print("Tell me another one of your interests.")
    else:
        least_objectionable_interest = ""
        for index, i in enumerate(potential_friend.interests):
            if len(i) > least_objectionable_interest:
                least_objectionable_interest = i
        partake_in_interest(least_objectionable_interest)
        begin_friendship()
        return
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm


Return to Bar

Who is online

Users browsing this forum: No registered users and 2 guests