Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:26:41+00:00 2026-06-02T22:26:41+00:00

This is a bit of a puzzle – I have created a small game

  • 0

This is a bit of a puzzle – I have created a small game for my kids that is not dissimilar to the likes of Bookworm and Wordsworth. 49 letters are chosen at random from the alphabet (stored in an array), and the kids click adjacent letters to make words. There is a check to match the words to a dictionary file (also in an array), and if the word is valid the chosen letters are replaced in the grid with more random letters. All fine so far.

What I would like to do next is to check the grid to see if there are any valid words left in it, a kind of game over if you like. The problem is that I have no idea where to actually start!

The letters in the grid can be dropped into an array easily enough, but I lack the skills to work out the jQuery or javascript code that can check the grid to for valid words (remembering that the letters have to be adjacent to each other). Letters are displayed in DIV elements as opposed to a table.

So far I have simply managed to lock up the browser in a multitude of loops with the problem only exacerbated because the code needs to run every time a word is correctly found and letters in the grid replaced.

I understand that this is more of a problem solving experiment than a coding question as such, so my apologies if this post breaks any rules here, but does anyone have any idea how best to go about this?

Cheers BS

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:26:50+00:00Added an answer on June 2, 2026 at 10:26 pm

    Start by getting all letters of a row. Then copy the first letter into a string and compare it to the dictionary. Next you take the two first letters and do the same. When you’ve reached 7 character length you take the 6 last letters and compare it to the dictionary. When you’ve done all checks in that row, move on to the next row. When all rows are completed do the same for collumns.

    psuedo code:

    for ($currentCollumn=1; $gridWidth > $currentCollumn; $currentCollumn++) {
        $collumn = get collumn as string
        for ($i=1;$i!=7;$i++) {
            get first $i characters of $collumn and compare to dictionary
            }
        for ($i=1;$i!=7;$i++) {
            get last $i characters of $collumn and compare to dictionary
            }
    }
    
    for ($currentRow=1; $gridHeight > $currentRow; $currentRow++) {
        $row = get row as string
        for ($i=1;$i!=7;$i++) {
            get first $i characters of $row and compare to dictionary
            }
        for ($i=1;$i!=7;$i++) {
            get last $i characters of $row and compare to dictionary
            }
    }
    

    EDIT: Version 2, since I didn’t realize the words weren’t limited to straight lines.

    start at every possible location.

    // define variables:
    booleanArray path[x][y] = false;  
    p = pointerlocation;  
    stack[] = p;  
    currentString = "";  
    

    p.up/.down/.left/.right checks path[][] where y+1, y-1, x+1, x-1 respectively. If it’s outside the bounds it will return false.

    The stack[] works like an x86 stack. Last in, first out.
    push() adds a new object onto the stack
    pop() gets the last object added to the stack and removes it from the stack

    function getAllTheStrings(p.x, p.y) {
        while (p) {
            path (p.x, p.y) = true;
            currentString += p.getCharacter();
            // check neighbors
            if (p.up) {
               stack.push(p.up, path, currentString);
            } 
            if (p.down) {
               stack.push(p.down, path, currentString);
            } 
            if (p.left) {
               stack.push(p.left, path, currentString);
            } 
            if (p.right) {
               stack.push(p.right, path, currentString);
            }
            // add current string to list possible words
            foundWords.push(currentString);
    
            // pop next item from stack
            overwrite variables with stored values of: p, path, currentString
    
            if (stack is empty) {
            p = false; // end loop
            }
        }
    }
    

    And that would be called by:

    function getWords() {
        for ($y=1; $gridHeight > $y; $y++) {
            for ($x=1; $gridWidth > $x; $x++) {
                getAllTheStrings(x,y);
            }
    }
    

    This function scales very badly with grid size since it has to check every single combination of possible paths. A 1×1 grid would take one test. A 2×2 would take 28 tests. At 3×3 I lost count at about 270 tests.

    After the loop is finished foundWords would be checked word for word against the whole dictionary. 5 found words and 100 words in the dictionary would give 500 comparisons. In reality the dictionary would have at least a thousand words.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a bit of a puzzle, I have these pseudo models: class Country(models.Model):
Hey guys this is a bit of a homework puzzle I'm working on and
This bit of code comes with new classes that are subclasses of UITableViewController... -
So I have this bit of code for x in range(x1,x2): for y in
I have this bit of code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
This question concerns running python files in terminal that are not stored in the
I have a project that must be compiled and run in 64 bit mode.
I bit of a puzzle to solve in CF here. You have a timestamp
I have encountered this interview puzzle and want to know its accurate answer. You
I have a bit of a puzzle (at least for me) which I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.