This is a repost of this challenge
Challenge
There is an old, popular riddle:
Find an English word with 8 letters that, taken away one letter, creates a new valid word. Repeat that until there are no letters left.
Example solution:
starting
staring
string
sting
sing
sin
in
I
Your task is to write a program, which takes a dictionary and outputs the longest word, that still occurs in the dictionary after repeatedly taking away a letter.
Rules
- All words will be lower case and contain only ASCII-letters
- If multiple valid words have the same length you can output any one of those
- The dictionary will never be empty
- If there isn't any solution in the dictionary, then you have to output nothing/return an empty list/a falsey value
- You're allowed to output a list representing the process of removing each letter (eg.
['this', 'his', 'is', 'i']
) - Default Loopholes apply
- This is code-golf, so the shortest answer wins!
Examples
In: ['this', 'hat', 'his', 'hi', 'is', 'i', 'a', 'at']
Out: this
In: ['pings', 'aid', 'ping', 'ad', 'i', 'in', 'a']
Out: aid
In: ['a', 'ab', 'bac']
Out: ab
In: ['a', 'aa', 'aaaa']
Out: aa
In: ['as', 'i', 'his', 'that', 'ping', 'pin', 'in', 'was', 'at', 'this', 'what', 'is', 'it', 'and', 'a', 'in', 'can', 'if', 'an', 'hand', 'land', 'act', 'ask', 'any', 'part', 'man', 'mean', 'many', 'has', 'stand', 'farm', 'eat', 'main', 'wind', 'boat', 'ran', 'heat', 'east', 'warm', 'fact', 'fast', 'rain', 'art', 'heart', 'am', 'arm', 'sit', 'train', 'sat', 'gas', 'least', 'fit', 'flat', 'cat', 'bit', 'coast', 'sand', 'beat', 'hit', 'party', 'wing', 'wash', 'bat', 'meat', 'suit', 'fat', 'meant', 'coat', 'band', 'win', 'seat', 'hat', 'salt']
Possible outputs:
1. stand (stand -> sand -> and -> an -> a)
2. heart (heart -> heat -> eat -> at -> a)
3. train (train -> rain -> ran -> an -> a)
4. least (least -> east -> eat -> at -> a)
5. coast (coast -> coat -> cat -> at -> a)
6. party (party -> part -> art -> at -> a)
7. meant (meant -> meat -> eat -> at -> a)
aid
it outputs["aid","ad","a"]
? \$\endgroup\$['a', 'ab', 'bac']
and['a', 'aa', 'aaaa']
, since solutions which turn the words to sets work for the given examples \$\endgroup\$['a', 'ab', 'bac']
=>ab
and['a', 'aa', 'aaaa']
=>aa
? \$\endgroup\$