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.
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.
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
"coconut", the output is
1 because in
"bananacoconut" there is only one
b, and for each portion of
"bacon" we need one
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
A non-negative integer representing the amount of meals that can be cooked.
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