My attempt to do it was like this, but at -997 I’m getting 998 instead of 996:
max_value = 1000
def calculate_parent_value(child_value):
if abs(child_value) == max_value:
return -child_value + 1
elif abs(child_value) == max_value - 1:
return -max_value if child_value > 0 else max_value - 2
else:
return -child_value + 1
calculate_parent_value(-997)
998
(and not 996). Is anyone able to fix the function ?