Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pure math solution in Clear category for Divide Gold: Rates Are Rising by H0r4c3
def winner_share(gold: int, sailors: int) -> int:
share1 = gold / (sailors + 2)
print(f'share1 = {share1}')
if sailors != 0:
share2 = gold / sailors
print(f'share2 = {share2}')
share3 = gold / (sailors + 1)
print(f'share3 = {share3}')
if sailors - 1 != 0:
share4 = gold / (sailors - 1)
print(f'share4 = {share4}')
if gold % (sailors + 2) == 0:
return share1 * 2
elif gold % sailors == 0:
return share2
elif gold % (sailors + 1) == 0:
return share3 * 2
elif gold % (sailors - 1) == 0:
return share4 * 2
else:
return gold
print("Example:")
print(winner_share(15, 1))
# These "asserts" are used for self-checking
assert winner_share(15, 4) == 6
assert winner_share(16, 4) == 4
assert winner_share(100, 11) == 20
assert winner_share(15, 1) == 10
assert winner_share(28, 2) == 14
assert winner_share(54, 4) == 18
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 23, 2024
Comments: