Problem 1.2: Balanced(100pts)
Hint: for more information on this problem (with more pictures!), please refer to this document.
Implement the balanced
function, which returns whether m is a balanced mobile.
A mobile is balanced if two conditions are both met:
- The torque applied by its left arm is equal to that applied by its right arm. Torque of the left arm is the length of the left rod multiplied by the total weight hanging from that rod. Likewise for the right.
- Each of the mobiles hanging at the end of its arms is balanced.
Planets themselves are balanced.
def balanced(m):
"""Return whether m is balanced.
>>> t, u, v = examples()
>>> balanced(t)
True
>>> balanced(v)
True
>>> w = mobile(arm(3, t), arm(2, u))
>>> balanced(w)
False
>>> balanced(mobile(arm(1, v), arm(1, w)))
False
>>> balanced(mobile(arm(1, w), arm(1, v)))
False
"""
assert is_mobile(m)
"*** YOUR CODE HERE ***"