Introduction to Artificial Intelligence Assignment 1
This is a relatively trivial HW intended to get you started with with Python. This homework requires you to write some code for manipulating representations of mobiles (the things with wires and colorful objects often found floating over babies heads in strollers and such). We'll restrict ourselves to simple ones with a binary branching structure.
At the top level, such mobiles consist of two parts: a left branch and a right branch. Each branch also consists of two parts: a rod that has a length, and an object at the end of the rod. The object can be either a simple weight or yet another mobile.
Your task is to write a function called balancedp that returns true if the mobile that is passed to it as an argument is balanced and returns false otherwise. More precisely, when passed a representation of a single mobile it returns a 1 if that mobile is balanced and a 0 otherwise.
A mobile is balanced if and only if the torque on its top left branch is equal to the torque on its top right branch AND if the sub-mobiles hanging off of these top branches are themselves balanced. Assume that the simple weights found at the leaves are always balanced. The torque on a branch is equal to the weight at end of the branch multiplied by the length of the branch. The weight of the branch is just the weight of the object hanging from it (assume the branch rods are themselves weightless).
A small set of mobiles, represented simply as lists of lists in python lists, can be used for testing. Both balanced and unbalanced mobiles are included in the collection. Use this collection to develop your code. You can use the python "import" statement to load these files for testing.
Bring a hardcopy of your code along with output from sample runs from the test collection to class on Tuesday 9/4. In addition, email me (in one plain ascii, non-tarred, non-gzipped, non-compressed or otherwise messed with file) your working python code.
Most of your grade will be based on whether or not your code works on a new set of balanced and unbalanced mobiles. However, I'll also take a look at generic things such as good coding style and the like.
This is an individual assignment. You can discuss the problem in general with others in the class to clarify things, but don't share specifics and don't share any code.