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?
Challenge
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:
voogunspgrygrobuns
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.
Test Cases
Word A | Word B | Sentence | Result |
---|---|---|---|
a | b | ab | a b |
ab | cd | abcd | ab cd |
ab | cd | abc | ab cd |
ab | cd | ac | ab cd |
ab | cd | bd | ab cd |
ab | cd | bda | ab cd ab |
ab | cd | aa | ab ab |
ooq | dr | ooqdr | ooq dr |
ooq | dr | oooqdr | ooq ooq dr |
groovy | unspeakable | voogunspgrygrobuns | groovy groovy groovy unspeakable groovy groovy unspeakable unspeakable |
a b
\$\endgroup\$