r/applescript • • Sep 04 '21
Need help with a word search solver in AppleScript.
So, I was feeling ambitious enough to make an attempt at a script that would solve a word search for you. However, it has proven to be a much more difficult task than I had thought, given the limited capabilities of AppleScript. Naively, I had attempted such a thing when I first learned about the scripting language, quickly to abandon the project. About a year later and it's one of the main side-projects I've been thinking about for a while now. While working on it, I've run into so many issues that I've been kind of burnt out on the whole project and also overwhelmed by how much actually goes into solving a word search.
If you would like to see what I have so far, you can find it via pastebin here. What the script does essentially is iterate through every letter in the array to find all the 'valid' positions it can check in, and then display whether a certain valid position is a leading letter to the selected word from the word bank. It may sound confusing, but I'll explain it better in the pipeline below.
The unfinished pipeline for my proposed script is as follows:
- Have the user manually input the array through an input medium (e.g., display dialog).
- Have the user manually input the words to look for through the same input medium.
- Interpret the strings as lists and format them to be processed by the script.
Iterate through every item in the array:
- Based off of the coordinates of the currently selected item, perform a series of transformations to calculate the coordinates of all eight positions around that item.
- Determine which of those positions don't exist on the array (e.g., coordinates that contain a value not within range) and which ones that do, adding those to a new list and labeling them as valid positions.
Iterating through every valid position, perform a check to see if the letter associated with those coordinates contribute to the currently selected word in the word bank.
- If so, set the currently selected item in the array to that position, and perform the valid position checks again. If nothing shows up, revert back to the previous position and continue iterating through the valid positions.
- If not, continue on iterating through the valid positions until either an associated letter is found or not.
As you can see, there are a ton of meticulous steps that go into solving a word search, and I'm just overwhelmed. I haven't figured out how to efficiently keep track of each variable, and when I do get onto something, there's a fundamental issue that prevents it from operating properly, forcing me to rewrite the entire thing. Also note that because of the way the lists and items in them are organized, the coordinate system is a little counterintuitive, as the y-axis ascends in the negative direction, but I guess that's one of the snags of AppleScript being a non-standard programming language.
Any help at all with this pointless ambition would be greatly appreciated. Thanks for reading.
(P.S., if it's any help to you, a picture of the paper I used to visually organize the word search is attached.)

EDIT: Apologies in advance for not putting any comments in the script, I'm lazy
2
u/brandelune Sep 05 '21
Nice !
One suggestion: when you put code online, add *all the comments you can* :-)
The code ought to be read as sentences with code implementation below (or above) the sentence. That's so much easier for people who don't have in mind all your variable names, etc.
2
u/copperdomebodha Sep 08 '21
I haven’t looked at your code yet, but I like this problem. Easy steps, hard data management problem.
I broke this into three steps. Find first characters, search around the first characters for the second character and it’s vector ( direction), run out the vectors to word completion.
Got all that handled, but managing the data is tricky. I’m creating a list of found characters records. Each found character has a nextCharacter item holding the record for the next character, if it is found.
All working, but tests with Multiple words found is challenging me. Not an issue on most word searches, but I want it to work on my test array of
Back soon…