I'm not sure what you intend to do here. I can give you umpteen chicken dishes for instance that share 50% of the same ingredients - namely chicken. However I can only eat chicken a couple of times a week before I'm tired of it. Buying in bulk can still have a good amount of variety to the specific ingredients especially if they're going to sit in the freezer, and you can just think of a new way of preparing it when you take it out. It doesn't need to become an algorithm.
The key is to fill your cupboards with the essential ingredients of cooking such as:
- tinned and paste tomato
- worcestershire sauce, soy sauce, balsamic vinegar, red wine vinegar, rice wine vinegar, apple cider vinegar, fish sauce
- herbs (grow your own where possible - coriander, origanum, basil, chives, sage, thyme, celery, rosemary, parsley) and spices (turmeric, cinnamon, cloves, coriander seed, mustard seed, garam masala, curry leaves, bay leaf, cumin, paprika, red pepper flakes, etc).
- butter, milk, olive oil, canola oil
- onions, garlic, root ginger, peppers, chilies, turmeric root, potatoes, sweet potato, vegetables of all kinds, good stock (or learn to make your own)
- flour, breadcrumbs, parmesan cheese, good quality brown sugar, glutinous rice (avoid long grain and instant), mixed nuts and nutty wheat for bread
- tinned or dry beans - black, butter, white, cannellini, lima, kidney, chickpeas
- red and white wine, coconut milk, white yogurt, cream, buttermilk
Out of that type of stock, which might cost upfront, you'll be able to create an infinite variety of food. And because you have the variety in your cupboard, you won't run out of individual ingredients very quickly, so you end up over the long run spending about the same as if you made the same thing every day - because after all the thing you make all the time still costs money for each ingredient, it's just more monotonous.