Introduction:
Inspired by this silly meme video, which states 'COLD BEER', but is slightly too large for the scrolling advertisement board, causing it to display either 'COLD BEE' or 'OLD BEER' instead.
Challenge:
Given a dictionary-list of words, output all ordered pairs of words which can form new words if you'd remove the first letter of the first word in the pair and last letter of the last/second word in the pair.
Or, perhaps a more straight-forward explanation and implementation approach:
- Filter the input-list so all words with its first letter removed form a new valid word from the list.
- Filter the input-list again so all words with its last letter removed form a new valid word from the list.
- Take the cartesian product of these two filtered list, to create a list of all ordered pairs of these words (making sure to not use the same word twice!).
Challenge rules:
- I/O is flexible.
- It's possible there are no valid pairs to be made from the input, in which case the result is an empty list.
- The output pairs should be ordered. So with the example,
["cold","beer"]is valid, but["beer","cold"]is not (unlesseerandcolboth would have been part of the input-list as well). - The input-list won't contain duplicates. But make sure to not use a single word as a pair. E.g.
["beer","bee","eer"]won't result in["beer","beer"]but[]instead.
General Rules:
- This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (e.g. TIO or ATO).
- Also, adding an explanation for your answer is highly recommended.
Test Cases:
Input: ["this", "is", "a", "test", "using", "the", "example", "cold", "beer", "with", "bee", "and", "old"]
Output: [["cold","beer"]]
Input: ["this", "eyes", "his", "eyesight", "eye", "is", "flow", "ear", "low", "earn"]
Output: [["this","eyes"],["this","earn"],["his","eyes"],["his","earn"],["flow","eyes"],["flow","earn"]]
Input: ["cold", "postal", "this", "his", "blow", "beer", "percentage", "old", "inside", "low", "exposed", "insider", "bee", "destiny"]
Output: [["cold","beer"],["cold","insider"],["this","beer"],["this","insider"],["blow","beer"],["blow","insider"]]
Input: ["no", "possible", "result", "here"]
Output: []
Input: ["beer","bee","eer"]
Output: []

["his","eyes"]in the second example? I have[["this","eyes"],["this","earn"],["his","eyes"],["his","earn"],["flow","eyes"],["flow","earn"]]for that one. \$\endgroup\$["cold","beer","old","bee","hosts","ghost","ghosts"]\$\endgroup\$iisn't part of the input-list. And fromthistoisyou're also removing two letters instead of just one. \$\endgroup\$