Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

algorithm - Find hidden words in adjacent words by comparing to a dictionary?

I'm working on a puzzle where I think the solution might be combining letters from one word with an adjacent word to make a new word.

For example. If a sentence reads "Benjamin chucked the ball onto the icy surface of the rink."

I'd like to code a way that finds the words "Bench" (BENjamin + CHucked) and "think" (THe + rINK).

Maybe the finished result would be a process that would use a dictionary file, compare all the possible iterations from a string of text (or file?) and then output the words found.

So start by comparing Benjamin to chucked. Use the B from first word, does that B make a word with the c from the next word? If yes, then output. If no, then try B with the next possibility, which is B + ch. Does that make a word? If not, then keep going. Does B+chu make a word? If not and there are no words in the dictionary that start with Bchu, then go back and grab the next letter from word 1, So Be+C... Be+ch... Be+chu... until all possible iterations with Benjamin and chucked are completed. Then move on to the next set of two words, which are "chucked" and "the".

Does that make sense?

Additional info: I imagine a solution that uses the first x letters from word one (the prefix) and then either the prefix or suffix from word two. So BENjamin and CHucks generates 'bench', while THe and rINK generates 'think'.

The input sting will like be over a thousand of characters and if 500 words from the dictionary are found this way, then that would be ok. And I imagine limiting the size of words found to 5 or more.

question from:https://stackoverflow.com/questions/65875523/find-hidden-words-in-adjacent-words-by-comparing-to-a-dictionary

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...