The calculations behind filling supermarket shelves are dizzyingly complex – but it all starts with the x and y you know from school