Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Is it a valid hidden word?

+2
−0

The Universal Crossword has a set of guidelines for crossword puzzle submissions.

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:

  • POOR HOUSE, RHO: is valid. Solution: POOR HOUSE
  • IMPROPER USE, PERUSE: is not valid. It appears separated by a space: IMPROPER USE, but the suffix is empty.
  • SINGLE TRACK, SINGLET: is not valid. It appears separated by a space: SINGLE TRACK, but the prefix is empty.
  • PLANE TICKET, ET: is not valid. The word appears separated by a space: PLANE TICKET, but it also appears contiguously: PLANE TICKET.

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.

  • SINGLE TRACK, SICK: is valid. Solution: SINGLE TRACK
  • YOU MUST DOT YOUR IS AND CROSS YOUR TS, YURTS: is valid. Solution: YOU MUST DOT YOUR IS AND CROSS YOUR TS
  • STAND CLEAR, STAR: is valid, even though there are two solutions: STAND CLEAR and STAND CLEAR
  • START A WAR, STAR: is not valid since the word is a prefix of the clue.
  • TO ME, 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
  • IMPROPER USE, 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 A-Z) and a clue (consisting of letters A-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.

Test cases

Valid:

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

Invalid:

IMPROPER USE, PERUSE
SINGLE TRACK, SINGLET
PLANE TICKET, ET
START A WAR, STAR
TWO BIRDS WITH ONE STONE, TONE
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Two stone (1 comment)

1 answer

+0
−0

Ruby, 128 bytes

->x,y{g=->c{c.chars.join" ?"}
!x[y]&&(x.match?(/.+#{g[y]}.+/)||(0...(y.size-1)).any?{x[/^#{g[y[0.._1]]}.+#{g[y[(_1+1)..]]}$/]})}

Attempt This Online!

bookends are found with a constructed regex that takes most of the bytes.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »