Send units from "container" A to B? (math question)

I feel like you’re overthinking this. In pseudocode this this just:

UnitsFreeInB = ContainerSize - UnitsInB
UnitsToSend = min(min(1, UnitsInA), UnitsFreeInB)
UnitstInA = max(0, UnitsInA - UnitsToSend)
2 Likes