Is it a valid hidden word?
In this challenge we are going to be concerned with their rules for hidden word themes. A hidden word clue consists of a clue and a word. It can either be a "word break" or a "bookend".
For a word break the word must not appear as a contiguous substring of the clue, but if all the spaces are removed from the clue, then it is a contiguous substring with a non-empty prefix and suffix. Some examples:
RHO: is valid. Solution:
PERUSE: is not valid. It appears separated by a space:
IMPROPER USE, but the suffix is empty.
SINGLET: is not valid. It appears separated by a space:
SINGLE TRACK, but the prefix is empty.
ET: is not valid. The word appears separated by a space:
PLANE TICKET, but it also appears contiguously:
For a bookend the word must appear as a combination of a non-empty prefix and a non-empty suffix of the clue, but is not a contiguous substring. Bookends may span word breaks, but are not required to. The clue must not appear as a contiguous substring to be a valid bookend.
SICK: is valid. Solution:
YOU MUST DOT YOUR IS AND CROSS YOUR TS,
YURTS: is valid. Solution:
YOU MUST DOT YOUR IS AND CROSS YOUR TS
STAR: is valid, even though there are two solutions:
START A WAR,
STAR: is not valid since the word is a prefix of the clue.
TOME: is valid. It can be split multiple ways including ways with empty prefixes and suffixes.
TWO BIRDS WITH TWO STONE,
TONE: is not valid since the word is a suffix of the clue
PERUSE: is not valid. It appears as a suffix and is not a contiguous substring:
IMPROPER USE, but the prefix needs to be non empty for a bookend.
You will take as input a word (consisting of letters
Z) and a clue (consisting of letters
Z and spaces) and you must determine if the word is a valid solution to the clue by the above rules.
If the input is a valid pair you must output one consistent value, if it is not you must output a distinct consistent value.
This is code golf so the goal is to minimize the size of your source code as measured in bytes.
POOR HOUSE, RHO SINGLE TRACK, SICK YOU MUST DOT YOUR IS AND CROSS YOUR TS, YURTS STAND CLEAR, STAR TO ME, TOME IN A PICKLE, NAP
IMPROPER USE, PERUSE SINGLE TRACK, SINGLET PLANE TICKET, ET START A WAR, STAR TWO BIRDS WITH ONE STONE, TONE