Chef Avillez is about to cook us some really nice meal. He is just waiting for us to give him some ingredients and to request a meal.
Task
Given a list of ingredients (strings matching /[a-z]+/
) and a requested meal (string matching /[a-z][a-z ]*/
) output the integer amount of meals Chef Avillez can make.
Algorithm
Each letter ([a-z]
) in the ingredient list contributes with one character for the soon-to-be-cooked meals. Each portion of our requested meal costs as many of each character as there are in the request string, excluding spaces.
For example, if our requested meal is "bacon"
and the ingredients are "banana"
and "coconut"
, the output is 1
because in "bananacoconut"
there is only one b
, and for each portion of "bacon"
we need one "b"
.
Input
A list of ingredients in any reasonable format, like
- a list of strings
- a list of lists of characters
- a (whatever-you-please)-separated list of ingredients, in a single string
and a requested meal in any reasonable format, like
- a string
- a list of characters
Output
A non-negative integer representing the amount of meals that can be cooked.
Test cases
A Python reference implementation is available.
['spam', 'spam', 'spam', 'spam', 'bacon', 'eggs', 'eggs', 'bacon', 'spam'], 'beans' -> 2
['bacon', 'bacon', 'bacon', 'bacon', 'bacon'], 'bacon' -> 5
['banana', 'coconut'], 'bacon' -> 1
['acon', 'bcon', 'baon', 'bacn', 'baco'], 'bacon' -> 4
['tomato', 'oregano', 'pizza', 'chocolate'], 'bacon' -> 0
['strawberries', 'figs', 'chocolate', 'sardines'], 'cod fish' -> 1
['these', 'are', 'some', 'random', 'words', 'wow'], 'or' -> 3
['some', 'more', 'delicious', 'ingredients', 'here'], 'bolognese' -> 0
['some', 'delicious', 'ingredients', 'here', 'are', 'bliss'], 'bolognese' -> 1
['some', 'bountiful', 'bagful', 'of', 'ingredients', 'here', 'are', 'bliss'], 'bolognese' -> 1
['some', 'bountiful', 'bagful', 'of', 'ingredients', 'here', 'are', 'bliss'] bolognese -> 1
as a test case, since it makes the duplicated letter the limiting factor, and includes an incomplete portion for a recipe (3o
s total, 2 needed for a recipe). \$\endgroup\$a-z
! \$\endgroup\$