It seems that the change in bodyweight should be a strictly increasing function of calories eaten minus calories spent. The first caveat to this claim is that calories in the food eaten do not equal the calories absorbed, which is what matters for weight gain. People differ in the efficiency of their digestion – that is what bariatric surgery relies on. Also, food labels use calories measured by the burn method (dry the food, burn it, measure the heat output), which ignores for example that coarsely chewed food chunks pass through the digestive tract relatively unchanged, thus contribute few nutrients to the organism. An extreme example is wholegrain flax (linseeds) that remain undigested due to a waxy coating. In nature, seed dispersal by birds relies on the indigestibility of the seeds.
Even if calories absorbed could be accurately measured, the type of food eaten would still matter for weight gain due to imperfect willpower. Some foods are more addictive than others, notably those rich in refined carbohydrates – an easy example is drinks that are essentially sugar-water. Consuming a given amount of calories from high-glycaemic-load sucrose makes people eat more sooner on average than ingesting the same calories from slowly digested whole grains or unsaturated fat. Similarly, ignoring willpower limitations is why abstinence-based programs to prevent sexually transmitted infections, which naively might be expected to be 100% effective, are in fact ineffective (Underhill et al 2007, doi:10.1136/bmj.39245.446586.BE).
There are various tricks to circumvent limited willpower to win the game against one’s future tempted self. To reduce temptation, food should be out of sight outside mealtimes (in cupboards, drawers, fridge) and unhealthy snacks should not be bought at all. Even seeing dishes and cutlery may trigger cravings, in which case these too should be placed out of sight when not in use.
Avoiding grocery shopping while hungry is an old piece of advice, which may be taken further by having someone else buy your food. Two people can even agree to grocery-shop for each other according to shopping lists exchanged beforehand. Online ordering may be a solution, but of course the merchants want customers to buy more, so advertise tempting foods with photos on their website. These ads can be blocked with some effort. A more sophisticated solution is to have one’s own user interface (front end) interact with the merchant’s website – scrape the data on inventory and prices, send commands to buy.