diethack: diet problem solver with dietary reference intakes in mind


I was curious how a diet conforming to USDA Dietary Reference Intakes may look like. I mean not only your usual protein, fat and carbs, but also a zillion other microelements and vitamins. To compute that diet, I needed a tool which can tell me in what proportions shall I mix regular food products from my local grocery store to meet the DRI requirements. It'd also be nice if such combination of products is the cheapest one. In other words, I needed to solve a variant of the classical diet problem. I couldn't find an open-source tool for that, so I built one myself. Have fun with it, you fellow nutrition maniacs!



Here's the diet I computed for myself using the products from local and online stores. I was so excited, I even ended up eating this stuff for quite a while! Prices are of the time of writing of course, they've changed since then.
Full report, shopping list and summary.

Just for fun, I also computed a diet meeting the same requirements as above, but composed of random products from USDA National Nutrient Database. There's no price information in it though.
Full report.

These examples are included in the distribution, you can build and play with them yourself.


It's a Python library. Through its API you define the goal as acceptable ranges for each element, specify which products to compose the diet of, run the solver to find the cheapest solution, and save the report.

Runs on Arch Linux, but with a reasonable amount of effort can be built on Windows, Mac OS X and many Unix-like operating systems.

Solves the diet problem. Finds in what proportions you need to mix the food products, so that all micro- and macroelements are within acceptable ranges, and the result is the cheapest possible.

Predefined and custom food products. Full USDA National Nutrient Database is included in the distrubution. You can use it as a base when defining your custom products available in your local stores.

Per-product mass limits. You can specify maximum allowed mass for each product, so you don't have to eat 10kg of oat meals per day.

Several types of reports. Full report shows detailed contribution of each of the products to the final solution. Shopping list shows what it says. Summary can be used when cooking the meal.


If you want to get in touch, please feel free to drop me a line.

Copyright 2015 Oleg Plakhotniuk