Advertisement
Vermiculus

Chef

Mar 25th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.37 KB | None | 0 0
  1. class Kitchen:
  2.     """A facility for interpreting the esoteric language 'Chef'.
  3.     """
  4.    
  5.     def __init__(self, recipe=""):
  6.         """Constructor
  7.        
  8.         Initializes lists for mixing bowls and baking dishes and
  9.             begins evaluating the recipe (taken in as a string).
  10.         """
  11.         pass
  12.    
  13.     class Bowl:
  14.         """One mixing bowl allowing for the basic operations.
  15.         """
  16.         pass
  17.    
  18.     class Dish:
  19.         """One baking dish allowing for the basic operations.
  20.         """
  21.         pass
  22.    
  23.     def _get_bowl(self, s):
  24.         """Returns the mixing bowl specified by this string.
  25.        
  26.         This method searches the string provided for the mixing bowl needed:
  27.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish.")
  28.         3
  29.        
  30.         If no ordinal for a mixing bowl is specified, it defaults to 1:
  31.         >>> getDish("Put zucchinis into the mixing bowl.")
  32.         1
  33.        
  34.         If there is no mention of any mixing bowls, this function returns None:
  35.         >>> getDish("I've got poop for brains.")
  36.         None
  37.         """
  38.         pass
  39.    
  40.     def _get_dish(self, s):
  41.         """Returns the baking dish specified by this string.
  42.        
  43.         This method searches the string provided for the baking dish needed:
  44.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish")
  45.         2
  46.        
  47.         If no ordinal for a baking dish is specified, it defaults to 1:
  48.         >>> getDish("Pour the 3rd mixing bowl into the baking dish")
  49.         1
  50.        
  51.         If there is no mention of any baking dishes, this function returns None:
  52.         >>> getDish("I've got poop for brains.")
  53.         None
  54.         """
  55.         pass
  56.    
  57.     def take(self, s):
  58.         """Take (ingredient) from refrigerator.
  59.        
  60.         This reads a numeric value from STDIN into
  61.             the ingredient named, overwriting any
  62.             previous value.
  63.         """
  64.         pass
  65.    
  66.     def put(self, s):
  67.         """Put (ingredient) into the [nth] mixing bowl.
  68.        
  69.         This puts the ingredient into the nth mixing bowl.
  70.         """
  71.         pass
  72.    
  73.     def fold(self, s):
  74.         """Fold (ingredient) into [nth] mixing bowl.
  75.        
  76.         This removes the top value from the nth mixing bowl and places it in the ingredient.
  77.         """
  78.         pass
  79.    
  80.     def add(self, s):
  81.         """Two uses.
  82.        
  83.        
  84.         Add (ingredient) [to [nth] mixing bowl].
  85.             This adds the value of ingredient to the
  86.             value of the ingredient on top of the
  87.             nth mixing bowl and stores the result
  88.             in the nth mixing bowl.
  89.        
  90.         Add dry ingredients [to [nth] mixing bowl].
  91.             This adds the values of all the dry ingredients
  92.             together and places the result into the
  93.             nth mixing bowl.
  94.         """
  95.         pass
  96.    
  97.     def remove(self, s):
  98.         """Remove ingredient [from [nth] mixing bowl].
  99.        
  100.         This subtracts the value of ingredient from
  101.             the value of the ingredient on top of the
  102.             nth mixing bowl and stores the result in
  103.             the nth mixing bowl.
  104.         """
  105.         pass
  106.    
  107.     def combine(self, s):
  108.         """Combine ingredient [into [nth] mixing bowl].
  109.        
  110.         This multiplies the value of ingredient by
  111.             the value of the ingredient on top of
  112.             the nth mixing bowl and stores the result
  113.             in the nth mixing bowl.
  114.         """
  115.         pass
  116.    
  117.     def divide(self, s):
  118.         """Divide ingredient [into [nth] mixing bowl].
  119.        
  120.         This divides the value of ingredient into
  121.             the value of the ingredient on top of
  122.             the nth mixing bowl and stores the result
  123.             in the nth mixing bowl.
  124.         """
  125.         pass
  126.    
  127.     def liquefy(self, s):
  128.         """Two uses.
  129.        
  130.        
  131.         Liquefy | Liquify ingredient.
  132.             This turns the ingredient into a liquid,
  133.             i.e. a Unicode character for output purposes.
  134.            
  135.             (Note: The original specification used
  136.             the word "Liquify", which is a spelling
  137.             error. "Liquify" is deprecated.
  138.             Use "Liquefy" in all new code.)
  139.        
  140.         Liquefy | Liquify contents of the [nth] mixing bowl.
  141.             This turns all the ingredients in the nth mixing bowl
  142.             into a liquid, i.e. a Unicode characters for
  143.             output purposes.
  144.         """
  145.         pass
  146.    
  147.     def stir(self, s):
  148.         """Two uses.
  149.        
  150.        
  151.         Stir [the [nth] mixing bowl] for number minutes.
  152.             This "rolls" the top number ingredients
  153.             in the nth mixing bowl, such that the
  154.             top ingredient goes down that number of
  155.             ingredients and all ingredients above it
  156.             rise one place. If there are not that many
  157.             ingredients in the bowl, the top ingredient
  158.             goes to tbe bottom of the bowl and all
  159.             the others rise one place.
  160.        
  161.         Stir ingredient into the [nth] mixing bowl.
  162.             This rolls the number of ingredients
  163.             in the nth mixing bowl equal to
  164.             the value of ingredient, such that
  165.             the top ingredient goes down that number
  166.             of ingredients and all ingredients above
  167.             it rise one place. If there are not that
  168.             many ingredients in the bowl, the top
  169.             ingredient goes to tbe bottom of the bowl
  170.             and all the others rise one place.
  171.         """
  172.         pass
  173.    
  174.     def mix(self, s):
  175.         """Mix [the [nth] mixing bowl] well.
  176.        
  177.         This randomises the order of the
  178.             ingredients in the nth mixing bowl.
  179.         """
  180.         pass
  181.    
  182.     def clean(self, s):
  183.         """Clean [nth] mixing bowl.
  184.        
  185.         This removes all the ingredients
  186.             from the nth mixing bowl.
  187.         """
  188.         pass
  189.    
  190.     def pour(self, s):
  191.         """Pour contents of the [nth] mixing bowl into the [pth] baking dish.
  192.        
  193.         This copies all the ingredients from
  194.             the nth mixing bowl to the
  195.             pth baking dish, retaining the order
  196.             and putting them on top of anything
  197.             already in the baking dish.
  198.         """
  199.         pass
  200.    
  201.     def set(self, s):
  202.         """Set aside.
  203.        
  204.         This causes execution of the innermost
  205.             loop in which it occurs to end
  206.             immediately and execution
  207.             to continue at the statement after
  208.             the "until".
  209.         """
  210.         pass
  211.    
  212.     def serve(self, s):
  213.         """Two uses.
  214.        
  215.        
  216.         Serve with auxiliary-recipe.
  217.             This invokes a sous-chef to immediately
  218.             prepare the named auxiliary-recipe.
  219.             The calling chef waits until the sous-chef
  220.             is finished before continuing.
  221.            
  222.             See the section on auxiliary recipes below.
  223.        
  224.         Serves number-of-diners.
  225.             This statement writes to STDOUT the contents
  226.             of the first number-of-diners baking dishes.
  227.             It begins with the 1st baking dish,
  228.             removing values from the top one by one and
  229.             printing them until the dish is empty,
  230.             then progresses to the next dish, until all
  231.             the dishes have been printed.
  232.            
  233.             The serves statement is optional, but is
  234.             required if the recipe is to output anything!
  235.         """
  236.         pass
  237.         return s
  238.    
  239.     def refrigerate(self, s):
  240.         """Refrigerate [for number hours].
  241.        
  242.         This causes execution of the recipe
  243.             in which it appears to end immediately.
  244.             If in an auxiliary recipe, the auxiliary
  245.             recipe ends and the sous-chef's first
  246.             mixing bowl is passed back to the calling
  247.             chef as normal. If a number of hours is
  248.             specified, the recipe will print out its
  249.             first number baking dishes before ending.
  250.         """
  251.         pass
  252.  
  253. k = Kitchen()
  254.  
  255. a = raw_input()
  256.  
  257. toks = a.split()
  258.  
  259. func = getattr(k, toks[0])
  260.  
  261. print func(toks[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement