| UT 104c Final Exam |
|---|
| Finished |
In Boggle, you are given a grid of letters, and need to form words using letters from the grid.
To form a word, you start at any square, then trace a path through the grid by moving from your current square to any adjacent square (in the four orthogonal or four diagonal directions). Each square you visit adds a letter to the word. You cannot visit the same square more than once.
For example, given the following grid:
ABCD
HGFE
IJOL
PONM
it is possible to form MOON, FLED, and HAG. HIGH is not a valid word you can form using the grid, because it requires visiting the same square (the H) more than once.
Given a grid and a target word, is it possible to form the target word according to the above rules?
The first four lines of input contain exactly four characters each, and specify the letter grid. The fifth line of input contains the target word, which will have length at least $$$3$$$ letters and at most $$$10$$$ letters.
"Letters" in this problem are uppercase ASCII characters A through Z.
Print POSSIBLE if it is possible to form the target word using the Boggle rules described above. Print IMPOSSIBLE otherwise.
ABCDHGFEIJOLPONMFLED
POSSIBLE
ABCDHGFEIJOLPONMHIGH
IMPOSSIBLE
ZZZZZZZZZZZZZZZZZZZZZZZZZZ
POSSIBLE
Duplicate letters in the grid are allowed (like the O in Sample Input 1.)
| Name |
|---|


