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 8248893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:21:02+00:00 2026-06-07T23:21:02+00:00

While putting together a Boggle solver, I ran into some strange behavior I was

  • 0

While putting together a Boggle solver, I ran into some strange behavior I was hoping someone could explain to me. I got the function to return a set of possible words, and all I seemed to be missing was a way to prevent the solver from including words which were created by visiting the same square twice in a play. I tried to create a list of already visited squares within the current play (a list of index numbers within the string representing the board) by iterating over the global variable seen (I know this would not be correct) which is used to memoize previously explored paths. However, simply initializing a variable with those values using:

previous_ind = [j for (pre, j) in seen]

within the recursive function find_bwords, somehow effects the index variable i and causes IndexErrors stemming from the last line in find_bwords.

seen = set() #(prefix, index) pairs

def boggle_words(board, minlength=3):
    "Find all the words on this Boggle board; return as a set of words."
    results = set()
    for i, sq in enumerate(board):
        if is_letter(sq):
            find_bwords(board, sq, i, results, minlength)
    return results

def find_bwords(board, pre, start, results, minlength): #adds to seen and results
    global seen
    #prev_ind = [j for (pre, j) in seen]  <---mystery culprit
    if (pre, start) not in seen:
        seen.add((pre, start))
        if len(pre) >= minlength and pre in WORDS:
            results.add(pre)
        if pre in PREFIXES:
            for i in neighbors(start, int(sqrt(len(board)))):
                #print 'index: ', i
                find_bwords(board, pre+board[i], i, results, minlength)

Here is a portion of the printout of indexes before introducing prev_ind:

index:  0
index:  1
index:  2
index:  6
index:  8
index:  12
index:  13
index:  14
index:  1
index:  2

and here is a portion after:

index:  0
index:  -7
index:  -14
index:  -21
index:  -28
index:  -35
index:  -42

Why is this happening?

To be clear, I am not looking for a solution to this assignment, I have solved it another way, I just want to understand what is happening in this instance.

  • 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-07T23:21:03+00:00Added an answer on June 7, 2026 at 11:21 pm

    The problem is on this line you are assigning to pre, overwriting the previous value it had:

    prev_ind = [j for (pre, j) in seen]  # <---mystery culprit
    

    Try changing it to this and it should work as you expect:

    prev_ind = [j for (pre2, j) in seen] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm putting together some demo pages, and one of the things I want to
I'm putting together a new app and, while I normally use JQuery for things
I'm putting together a Rails app, and I've run into a bit of an
I am putting together a Samba-based server as a Primary Domain Controller, and ran
I am putting together a program that takes 20 random numbers, sorts them into
I'm putting together a multi-language system, but am running into issues with orphaned processes.
I have a simple problem while putting text in multiple table! please have a
Hi i am getting error while putting validations for email in PHP5.2 see my
While deveoping a site (using Forms authentication and InProc sessionstate) a frequently run into
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I

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.