39
2
Introduction
After a day of drinking and watching the world cup, you sit down to play friendly game of boggle. Tempers rise as you are accused of wasting everyone's time with nonsense words that aren't even on the board! You may be seeing double, but surely you're thinking straight enough to write a program that will verify that your words are on the board.
Your Task
Write a program, script, or function that takes a boggle board and a word as input, and returns True if the word is on the board and False if the word isn't.
The input will be in the form of six \n
delimited lines. The first five lines will comprise the 5x5 boggle board and will each contain five capital letters. The sixth line will contain the word-in-question, also in all capital letters.
Sample input:
AJNES
TNFTR
LSAIL
UDNEX
EQGMM
DAFTER
The output can be anything that unambiguously signifies True or False in your programming language of choice and adheres to standard conventions of zero, null, and empty signifying False.
Sample output for above input:
1
I/O Guidelines
- The input may be read from stdin, and answer output to stdout.
Or
- The input may be a single string argument to a function, and answer be the return value of that function.
Boggle Rules
- A word is 'on the board' if you can construct the word via a path of consecutive, adjacent, non-repeating tiles on the board.
- A tile is considered adjacent to the eight tiles that surround it (diagonal paths are allowed). Tiles on the edge of the board are adjacent to only five tiles. Tiles in the corner are adjacent to only three.
- Consecutive letters in the word must be adjacent, the
i
th letter in the word must be adjacent to thei-1
th andi+1
th. - A letter may appear in a word more than once, but you cannot use the same square on the boggle board more than once per word.
- The online boggle site wordsplay.net may be useful if you have never played boggle before, but want to get a feel for these rules.
Unlike regular boggle:
- You do NOT have to worry about the word being a valid English word.
- There will be NO
Qu
single tile. - The word-in-question may be of any length > 0
Example
On the board of
AJNES
TNFTR
LSAIL
UDNEX
EQGMM
These words should return True: FATE, DATING, STANDS, LIFTS.
These words should return False: SADDEN, SULTANS, EXIST, SUEDE, QUEST
This is a code-golf challenge, so shortest code wins!
Boggle is normally a 4x4 board. – mbomb007 – 2018-04-30T19:26:34.577
Does the board wrap around? I can't remember – Claudiu – 2014-06-13T21:42:28.663
No it doesn't wrap, I updated the clarification about adjacency to reflect this. – turbulencetoo – 2014-06-13T21:44:02.023
Can the path cross itself (diagonally)? – Martin Ender – 2014-06-14T08:39:03.887
@m.buettner Yep – turbulencetoo – 2014-06-14T14:44:46.997