4
I've been using a library called Djangular recently, which integrates Django and Angular.
After a while I thought 'Wouldn't it be fun to programmatically generate portmanteau?'
Here are some examples (e.g. testcases):
Django + Angular -> Djangular
Camel + Leopard -> Cameleopard
Spoon + Fork -> Spoork
Ham + Hammer -> Hammer
The general rule is to find the first common letter working backwards on first word, and working forwards on the last word. Not all portmanteau can be found this way though...
I've deliberately picked 'simple' ones to generate (for instance we're ignoring things like Zebra + Donkey = Zedonk, which is too arbitrary to generate programmatically - the correct behaviour).
Ties can be resolved eitherway - suppose you have cart + ante
- both carte
, (since t is the last common letter in the first word) and cante
, (since a is the first common letter of the last word) are value.
Unfun loopholes are not allowed (including pulling 'solved' examples off wikipedia)
This is code golf, so shortest answer wins. I'll pick the winner a month from posting. Please post the output for all your code.
Could you elaborate on the rules for double letters? It seems that they are omitted if they appear in the first word but are kept if they appear in the second? Or is it that double vowels are omitted but double consonants are kept? – Martin Ender – 2015-08-07T07:20:32.130
Why isn't the double letter in hammer shortened to
hamer
? – Beta Decay – 2015-08-07T08:24:57.840Shouldn't it be Cameopard? e is the first common letter in the first word. – Sean Latham – 2015-08-07T09:00:53.593
Do I understand right that you want to get the longest portmanteau by finding a pair of matching letters in the two words that come as close as possible in the concatenated string? – xnor – 2015-08-07T09:06:53.860
@sp3000 is it not obvious they have to be common? Also I'll try and clarify double letters. – Pureferret – 2015-08-07T12:08:05.857
2Read literally, "latest in first word, earliest in last word" would mean
Spoon + Fork -> Spoork
if we take the secondo
to be the latest in the first word. Similarly, the commont
would meanCroissant + Donut -> Croissant
. Another example, with earliest in last word this time, would bemock + cocktail = mococktail
. I'm not sure if I'm just missing something major or... – Sp3000 – 2015-08-07T12:29:47.143@Sp3000 The "that are closest" part of the definition seems the most descriptive (even though there's an error in the sentence, it says "first" twice instead of "first" and "last"). The rest just makes it more confusing. By that definition, for Croissant and Donut, the solution would be Croissanut, since there's only 3 letters between the two n's of CroissantDonut. – Reto Koradi – 2015-08-07T14:50:15.280
@RetoKoradi I realise now that was a bad example. I've made edits appropriately – Pureferret – 2015-08-07T16:12:56.000
@Sp3000 both should be valid. I'll add that in. – Pureferret – 2015-08-07T16:25:03.853
Going back to
mock + cocktail
, is itmocktail
(k
is last common letter of first) ormococktail
(c
is first common letter of second)? Or does it not matter? – Sp3000 – 2015-08-07T16:30:01.6602This question is still very confusing. The title asks for the longest overlap, and I'm not sure what the body of the question is asking for, but whatever it is seems to favour shorter overlaps. – Peter Taylor – 2015-08-07T17:28:31.867
1Perhaps we could use a system like this for choosing which overlap is best: the final 'score' of each option is calculated with
(final word length + letters overlapped) * (1 - abs(amount of first word used - amount of second word used))
. For example,django + angular = djangular
uses 5/6 ofdjango
and all ofangular
, a difference of 1/6. Subtract that from (the final length of 9 + the overlap of 3), and you get a total score of 10, by far the highest possible. I'd be glad to clarify any questions about this system! – ETHproductions – 2015-08-07T18:02:04.2831I still don't understand this part:
The general rule is to find the first common letter working backwards on first word, and working forwards on the last word.
Does one of them take priority? – xnor – 2015-08-07T22:04:32.173@xnor nope, neither takes precedence. 'Ties can be resolved eitherway...' – Pureferret – 2015-08-08T14:46:42.887