Tuesday, September 16, 2014

Algorithms

   Thinking of something that I do everyday that could be expressed as an algorithm is not easy task. After much consideration, I decided that the most obvious algorithm that I use everyday is what to wear. Expressing the process to someone can happen in many different ways. The first way I could express this, is if I know exactly what I want to wear. If I know what I am wanting to wear the algorithm would be straight forward and the function would look like this:
   def Dress():
      put_on(pants)
      put_on(shirt)
      put_on(shoes)

In this scenario the function is easily excited and really doesn’t have a bad “Big O” input. The second scenario that could happen with my dressing algorithm is if I know what I want to wear, but I am unsure if the clothes I want are washed our not. This function when described to a person or computer would look like this:
   def Dress():
      if not is_dirty(shirt):
         put_on(shirt)
      else:
         put_on(clean_shirt)
      if not is_dirty(pants):
         put_on(pants)
      else:
         put_on(clean_pants)
      put_on(shoes)

In this scenario the function Dress() is a bit more complex, I am required to do a few extra steps to find my outcome. The final scenario is a bit longer, and would be rather spacey to type out so I will describe it. In the third scenario I would base what I am going to wear that day on if it is clean or not and if the temperature is in a certain range at that time. This function would have around twelve steps and take a lot longer based on how many inputs I have. 

   Describing all of these functions to a robot would be very easy to do, given the two examples above, a robot could easily be programed to run this. If I were to implement this algorithm with a computer, it would be very, very easy to do so. All I would need to do is write out a few more logic statements and it can easily return the outcome variable.  

   My outfit algorithm is not the fastest one, I would easily save time by preemptively sorting my clothes so I would not have to do the clean or dirty check in it. Other than that one fix, I don’t think that I could make it anymore efficient.

   If I had to share my algorithm verbally with people it would go something like this. The first step the the Dress() function is to pick out a shirt from your closet, check to see if the shirt is dirty, if it is, put it into the hamper, if not, put on the shirt. Next, pick out a pair of pants from the closet, check to see if the pants are dirty, if it is, put in into the hamper, if not, put on the pants. Finally, select a pair of shoes that you would like to wear and put them on. 


No comments:

Post a Comment