16
2
Background
Three years ago, this guy Tom Murphy got it into his head to extend the idea of a portmanteau to all words in a language and called this a portmantout (portmanteau plus tout [French for all]). Defining English as a list of 108,709 words, he managed to find a sequence of 611,820 letters with the following two properties:
- Every English word is contained in the string.
- Some neighborhood containing any two adjacent letters in the string is an English word.
Here's a link to a page on which this portmantout can be found (along with a video explanation).
A portmantout
The first of the two properties of a portmantout is easy to understand. The second may require some explanation.
Basically, words must overlap. "golfcode" will never appear in a portmantout of English, as there is no word there that contains the "fc". However, you might find "codegolf" in a portmantout, for "ego" bridges the gap (and all other pairs of letters are in either "code" or "golf").
Your task:
Write a program or function that takes a list of strings and returns any portmantout of the list.
This Python 3 code will verify a portmantout.
Test cases
All lists are unordered; that is,
{"code", "ego", "golf"} -> "codegolf"
{"more", "elm", "maniac"} -> "morelmaniac" or "morelmorelmaniac" or "morelmorelmorelmaniac" or...
Would a morelmaniac be some sort of mycologist?
{"ab", "bc", "cd", "de", "ef", "fg", "gh", "hi", "ij", "jk", "kl", "lm", "mn", "no", "op", "pq", "qr", "rs", "st", "tu", "uv", "vw", "wx", "xy", "yz", "za"} -> "abcdefghijklmnopqrstuvwxyza" or "rstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" or any 27+ letters in order
And why not? The massive one on Murphy's site, if your code executes within reasonable time.
Rules
- Your code must halt.
- You need not return the same portmantout with each execution.
- You may assume all strings consist of only lowercase letters
a
throughz
. - If no portmantout is possible, your program may do anything. Ex:
{"most", "short", "lists"}
- Standard rules for I/O and loopholes apply.
This is code-golf, so the shortest solution (in bytes) in each language wins! Happy golfing!
Sandbox – Khuldraeseth na'Barya – 2018-06-06T23:02:15.377
1Maybe some test cases? – Adám – 2018-06-06T23:20:48.430
{"sic", "bar", "rabbits", "cradle"} -> "barabbitsicradle"
{"mauve", "elated", "cast", "electric", "tame"} -> "mauvelectricastamelated"
(more test cases) – sundar - Reinstate Monica – 2018-06-07T00:19:24.3802Yeah, maybe a testcase where a word needs to be used twice – ASCII-only – 2018-06-07T01:04:33.830
Can we return all possible portmantouts? – Erik the Outgolfer – 2018-06-07T08:30:35.193
Will we ever get one word entirely contained in another (e.g.
meow
andhomeowner
)? – None – 2018-06-07T14:57:14.077Is it okay if the program halts with probability 1, but could theoretically run forever? – None – 2018-06-07T15:01:57.687
2Will we ever get 1-letter words? – None – 2018-06-07T15:11:36.160
how do you verify that it returns a different one?
https://www.random.org/analysis/dilbert.jpg
Related, not similar & old enough to be dead. – Magic Octopus Urn – 2018-06-07T18:24:08.577
@fortran The answer poster must prove that their answer is valid, not the community. – user202729 – 2018-08-03T03:28:48.223
@Mnemonic (1) I think there is a meta post about that, that says "work with probability 1 for all possible input". (2) The question doesn't specify that, so I don't see why not. Given that it's guaranteed that there is a portmantout, programs can simply filter out those 1-character ones.
– user202729 – 2018-08-03T03:31:10.453@user202729 if you have to explain a joke, it's not funny anymore – fortran – 2018-08-07T09:17:50.467