26 lines
846 B
Python
26 lines
846 B
Python
'''
|
|
Bear Bill wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Bill and Bob weigh a and b
|
|
respectively. It's guaranteed that Bill's weight is smaller than or equal to his brother's weight. Bill eats a lot and his weight is tripled
|
|
after every year, while Bob's weight is doubled after every year. After how many full years will Bill become strictly heavier than Bob?
|
|
|
|
Example 1
|
|
Input:
|
|
a = 4; b = 7
|
|
Output:
|
|
2
|
|
'''
|
|
|
|
class Solution(object):
|
|
def solve(self, a: int, b: int) -> int:
|
|
print("Initial weights - Bill:", a, "Bob:", b)
|
|
years = 0
|
|
while a <= b:
|
|
a *= 3
|
|
b *= 2
|
|
years += 1
|
|
print(f"After year {years}: Bill's weight = {a}, Bob's weight = {b}")
|
|
return years
|
|
|
|
s = Solution()
|
|
print(s.solve(4, 8)) # Output: 2
|