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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:29:43+00:00 2026-06-14T06:29:43+00:00

I have a single-threaded Python module (for resolving the n-Queen problem) with this important

  • 0

I have a single-threaded Python module (for resolving the n-Queen problem) with this important method:

def step(self):
    r = Random()        
    poz = r.choice(self.available)   #!!!problem here
    #poz = 9 #this will work
    for p in self.available:
        if self.collision(poz, p):   # this method fails with the usage of random
            self.available.remove(p)
    self.state.queens.append(poz)
    self.debug()
    return True

The method will work fine if I give it a constant value like 9 or anything else, but if I want to use the random function choice to select a value from the available (a list of numbers) the collision() method fails to work properly by missing some.

Here is the collision method if it helps:

def collision(self, a, b):
    x1, y1 = a / self.n, a % self.n
    x2, y2 = b / self.n, b % self.n  
    return x1 == x2 or y1 == y2 or abs(x1 - x2) == abs(y1 - y2) 

Basically it checks if a chess square “b” is attackable by the queen “a”

  • 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-14T06:29:45+00:00Added an answer on June 14, 2026 at 6:29 am

    Found answer here

    Remove items from a list while iterating

    replaced the iteration with

    self.available = [x for x in self.available if not self.collision(poz, x)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this service which is Singleton and Single threaded and serves bunch of
Suppose I have a function in a single threaded program that looks like this
I have a single-threaded application that uses 3 SQLite databases in 3 different files
I have a single-threaded Rails app running on thin in single-threaded mode on Heroku
I'm at the end of my rope here: I have a single-threaded C++ program.
[Cross-posted from lib-curl mailing list] I have a single threaded app (MSVC C++ 2005)
I have a multi-threaded program. I want to embed a python interpreter. I don't
I have a single threaded executor service for fetching some data over the network.
I have a simple single threaded utility written in C# that inserts data into
Possible Duplicate: Are C# arrays thread safe? I have a program that is single-threaded

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.