Sometimes dinner menus can have long winded names. It's much easier for the waiter to write an abbreviation that unambiguously identifies the dish.
For example, given this list:
beef burger chicken burger chicken nuggets
c n matches
beef burger and
Write a program of function that identifies one or more items that match an abbreviation.
- The abbreviated string to find.
- A list of items to search.
You may change this order and use any suitable data types.
- If the abbreviation does not match any items:
- If the abbreviation unambiguously matches an item: output the unabbreviated item.
- If the abbreviation ambiguously matches several items: output a comma separated list of words that would make the selection unambiguous, followed by a question mark. The order is not important. Extra spaces are permitted.
Each word in the abbreviation and the items is considered separately. If an abbreviated word matches the start of an item word, the item is a potential match. If none of an item's words start with any if the abbreviated words, that item is not a match.
Abbreviated words can be in any order.
An abbreviated word cannot be used to match multiple item words and visa-versa.
Abbreviations only match the start of words.
Assume no item will contain all of the words of another item. For example, you will never have
beef burger and
beef cheese burger.
Given this list:
beef burger crispy chicken burger grilled chicken burger chicken nuggets chocolate cone strawberry cone vanilla cone
These abbreviation give the specified output:
fish Not found cones Not found chicken cone Not found nilla Not found v vanilla cone be beef burger c n chicken nuggets b b beef burger c b c crispy chicken burger c b crispy,grilled? bu beef,crispy,grilled? or beef,crispy chicken,grilled chicken? ch crispy,grilled,nuggets,cone? or crispy chicken,grilled chicken,nuggets,cone?
This is code golf. The shortest answer in bytes in 12 days wins acceptance. (I would have made it one week, but I won't be around for that.)