Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Oh no, Santa spilled wine all over his great book. Now most of the letters are illegible. How will Santa now know who is groovy and who is unspeakable?
There was once a sequence of words, like this:
groovy groovy groovy unspeakable groovy groovy unspeakable unspeakable
However, most of the letters have gone missing and now it looks like this:
v oo g unsp gr y gro b uns
Then squashed together:
Your task is to recover the shortest sequence of words that could reduce to the given damaged string.
Note: The words will never have any overlapping characters. Since the book uses different words in different languages you need to handle different words.
|Word A||Word B||Sentence||Result|
|ab||cd||bda||ab cd ab|
|ooq||dr||oooqdr||ooq ooq dr|
|groovy||unspeakable||voogunspgrygrobuns||groovy groovy groovy unspeakable groovy groovy unspeakable unspeakable|