optimal eating

optimal eating
Photo by Anh Nguyen / Unsplash

If you haven't read the teaser for this post, you should do so now! Read it here:

[teaser] optimal eating
What do Domino’s drivers, MLB baseball teams, Delta Air Lines, the U.S. military and traveling salesmen all have in common? They all benefit from a branch of mathematical optimization known as linear programming.

If you want to jump straight into using my app, download the files here and keep them in the same folder:

nutrition_optimization.exe

As Casey alluded to in the teaser above, he and I developed an app that optimizes your diet. It gives you the guaranteed, most efficient amount of each different type of food to eat per day to maximize your nutrition while minimizing the cost.

Here's how it works:

nutrition.csv (how to use the spreadsheet)

First, download both the app (nutrition_optimization.exe) and the spreadsheet (nutrition.csv). Open the spreadsheet in Excel or similar. It should look like this:

Don't let all the information intimidate you! It's quite simple. Here's what each column means:

Column name Description
low The minimum number of servings of that food each day
high The maximum number of servings of that food each day
category The broad category that the food falls into
name The name of the food
serv The grams per serving of that food
tot_serv The total number of servings per container of food
cal/fat/carb/prot The calories/fat/carbs/protein per serving of food
price The total price of the whole container of food

You can edit this spreadsheet to your heart's content! I've prefilled it with foods from Walmart just to give some sample data.

Let's look at the row for “great value large white eggs, 60 count.” You see that the minimum number of eggs per day is 0. The maximum number of eggs per day is 6 (because I don't want to eat more than 6 eggs each day!). For the rest of this, I just got the information from the nutrition label (which some grocery stores even publish on their website):

One egg weighs approximately 50 grams, so I put “50” in the “serv” column. There are 60 servings per container, so I put that in the “tot_serv” column. Next I enter the number of calories, fat, carbs, and protein per serving in their respective columns. Finally, under “price,” I enter the total cost of the container of eggs.

If you have any questions about this, send me a message using the button below and I'll give you some help!

nutrition_optimization.exe (how to run the program)

Once you have all your foods entered into the spreadsheet, save it then double-click on nutrition_optimization.exe to run it. You will likely get lots of warnings that the file might be dangerous or something like that. I promise that it's very safe!

A blank window will pop up for a bit. It looks like this:

Just be patient. It will eventually disappear. Nothing else will happen, but you'll notice an extra file in the same folder called “results.txt.”

results.txt (how to interpret the results)

When you open “results.txt,” it will look like this:

The daily cost is how much all the food in your results will cost per day, the weekly cost gives you the cost per week, and the monthly cost gives you the cost per month.

The next table gives you the daily nutritional information. In the image above, you'll see that the daily intake is 2050 calories consisting of 65 grams of fat, 290 grams of carbs, and 98 grams of protein. This is based on a “standard” diet of 2000 calories with good nutritional balance. If you're interested in a different number of calories, or different proportions of nutrients, send me a message using the button below!

Finally, we get to the best part! The last table tells you how much of each food to use each day. This table is actually my current daily diet (which is serving me quite well)! If you don't like the number of servings of each food, you can adjust the "low" and "high" columns for each food. For example, if you don't want to eat 6 eggs per day, change the "high" column for the eggs to be lower than 6.

Unfortunately, the app can't design a recipe for you! You'll just have to get creative! If you have a particular recipe in mind, enter all the ingredients into the spreadsheet, then set their minimum values to at least the amount needed for the recipe.

In a later post, I'll share the recipes I use based on the optimization in this app!