13
I got to wondering yesterday if I could write a program to comb through a given word search and output the answers. It was actually surprisingly easy. Now I wonder just how small we can get.
Rules
- Your first input is a string or collection of n lines, each of which is n characters long
- Your second input is a list of words in any format to find in the puzzle
- All words in the search list are guaranteed to be in the puzzle
- Words can be oriented in any of the four cardinal directions, as well as diagonally both forwards and backwards
- Only uppercase A-Z characters will be present in the puzzle
- Your code must find every word in the the search string, and output the coordinate position of the starting letter, where 0,0 is the top left character.
- In the event that you locate more than one instance of the same word, you may handle it however you like. Output it multiple times, or only once, it's up to you
Examples/Test Cases
Given the following board:
ABCD
EFGH
IJKL
MNOP
And the following search string:
ABCD,CGKO,POMN,NJF,AFKP,CFI,LGB,MJGD
Your program should output the following, in any order:
ABCD at 0,0
CGKO at 0,2
PONM at 3,3
NJF at 3,1
AFKP at 0,0
CFI at 0,2
LGB at 2,3
MJGD at 3,0
As always, shortest answer wins
6Welcome to PPCG! Nice first challenge! – AdmBorkBork – 2018-04-20T18:52:53.600
2Similar, the only real difference seem to be the inclusion of the location in the output. – FryAmTheEggman – 2018-04-20T18:57:30.513
@NL628 Yes, all search words are guaranteed to be in the puzzle. If there is more than one occurence, you can either output it both times or ignore it the second, it's up to you. – morpen – 2018-04-20T19:07:14.203
@JonathanAllan Great idea. I will update it as you suggested. – morpen – 2018-04-20T19:08:11.400
1@RickHitchcock Yes it should :) – morpen – 2018-04-20T19:17:57.833
@JonathanAllan I addressed this seconds before you posted your question, but yes, every word is guaranteed to be present, and you may output any coordinate you wish, as many as you want. – morpen – 2018-04-20T19:18:48.120
Will letters appear on the board more than once? – Oliver – 2018-04-20T19:53:48.517
@Oliver They definitely could. The example is just that - an example. The algorithm should be able to solve any word search – morpen – 2018-04-20T19:55:45.213
Can the coordinates be 1-indexed? – Stewie Griffin – 2018-04-22T17:35:02.340
Can I take the input as a function parameter? Do I have to read it from stdin? – Peter Lenkefi – 2018-04-24T18:40:26.377