32
3
A portmanteau word is a combination of two words that takes part of each word and makes them into a single new word. For example, lion + tiger => liger.
Let's write a program to generate portmanteaus from a pair of input words. Computers aren't the best at English, so we'll need to establish some rules to ensure that the output portmanteaus are pleasant to the eye and ear.
(Examples here are shown with a separator between the prefix and suffix for clarity: li|ger
. However, the program's actual outputs should not have a separator: liger
.)
- Each portmanteau will consist of a nonempty prefix of the first word concatenated to a nonempty suffix of the second word: yes to
li|ger
, no to|iger
. - If the prefix ends with a vowel, the suffix must start with a consonant, and vice versa: yes to
lio|ger
orl|er
, no tolio|iger
orl|ger
. You may decide whether to county
as a vowel or a consonant. Your solution must pick one option and stick with it, however. - The resulting word must not contain either of the original words in full: yes to
lio|ger
, no tolion|iger
orli|tiger
.- This rule holds even if the portion in question is formed from parts of both words: with input of
two
+words
, outputtw|ords
is still illegal because it contains the substringwords
. (The only valid output for this pair would bet|ords
.)
- This rule holds even if the portion in question is formed from parts of both words: with input of
Your program or function must take two words and output/return a list of all pleasant portmanteaus that can be formed from those words in that order.
Details
- Standard input and output methods apply. Standard loopholes are forbidden.
- Words will consist only of lowercase letters (or, if you prefer, only of uppercase letters).
- You may take the two input words as a list, tuple, two separate inputs, a single string with a non-letter delimiter, etc.
- Output format is similarly flexible; if you return or output a string, it should be delimited such that it's clear where one portmanteau word ends and the next one begins.
- There should be no delimiters inside a portmanteau word.
- It's okay if your output list includes duplicate results; it's also okay to remove duplicates.
Test cases
> lion, tiger
< liger, ler, liger, lir, lioger, lior
> tiger, lion
< tion, ton, tin, tigion, tigon, tigen
> spoon, fork
< sork, spork, spork, spok, spoork, spook
> smoke, fog
< sog, smog, smog, smokog
> gallop, triumph
< giumph, gumph, gariumph, gamph, gaph, gah, galiumph, galumph, galliumph, gallumph, galloriumph, gallomph, galloh
> breakfast, lunch
< bunch, brunch, brench, brech, breh, breanch, breach, breah, breakunch, breakfunch, breakfanch, breakfach, breakfah, breakfasunch
> two, words
< tords
> harry, ginny (if y is treated as a consonant)
< hinny, hanny, hany, hay, harinny, harrinny
> harry, ginny (if y is treated as a vowel)
> hinny, hy, hanny, hany, harinny, hary, harrinny
Reference solution
Here's a reference solution in Pip (treats y
as a consonant).
This is code-golf: the shortest answer in each language wins!
Related. More distantly related. – DLosc – 2018-07-03T04:01:15.167
must the delimiter be constant or can i put a bunch of spaces between the words? – Asone Tuhid – 2018-07-11T13:54:28.183
@AsoneTuhid Sure, variable amounts of whitespace would be an acceptable delimiter. The only requirement is that "it's clear where one portmanteau word ends and the next one begins." – DLosc – 2018-07-12T16:14:09.690