Fulcrum def can_balance(items): Each element in items is a physical weight, a positive integer instead of some sort of helium balloon. Your task is to 0ind and return a fulcrum position in this list of weights so that when balanced on that position, the total torque of the items to the left of that position equals the total torque of the items to the right of that position
Looking for assistance with this question:
Fulcrum
def can_balance(items):Each element in items is a physical weight, a positive integer instead of some sort of helium balloon. Your task is to 0ind and return a fulcrum position in this list of weights so that when balanced on that position, the total torque of the items to the left of that position equals the total torque of the items to the right of that position. The item on the fulcrum is assumed to be centered symmetrically on the fulcrum, and does not participate in the torque calculation.
In physics, the torque of an item with respect to the fulcrum equals its weight times distance from the fulcrum. If a fulcrum position exists, return that position. Otherwise return -1 to arti0icially indicate that the given items cannot be balanced, at least without rearranging them.
items |
Expected result |
[6, 1, 10, 5, 4]
|
2 |
[10, 3, 3, 2, 1]
|
1 |
[7, 3, 4, 2, 9, 7, 4]
|
-1 |
[42] |
0 |
The problem of 0inding the fulcrum position when rearranging elements is allowed would be an interesting but a far more advanced problem normally suitable for a third year computer science course. However, this
Trending now
This is a popular solution!
Step by step
Solved in 2 steps