Question

Following are the steps (algorithm) to obtain a solution for Queen Puzzle heuristically: a, Divide n...

Following are the steps (algorithm) to obtain a solution for Queen Puzzle heuristically:

a, Divide n by 12 Remember the remainder (n is 8 for the eight queens puzzle)

b. Write a list of the odd numbers from 1 to n in order, if the remainder is 8, switch pairs (i.e. 3, 1, 7, 5. 11.9....)

c. if the remainder is 2, Switch the places of 1 and 3, then move 5 to the end of the list

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm:

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

This is a very big question.
I have solved all of them.
Please give me an upvote dear, Much Appreciated.!!

def get_solution(n):
    """
    return the value of the N-Queen problem solution
    """

    # STEP (a)  Divide n by 12 Remember the remainder
    remainder = n % 12

    # STEP (b)  Write a list of the odd numbers from 1 to n in order
    odd_numbers = [i for i in range(1, n + 1, 2)]
    if remainder == 8:
        # Switch Pairs
        for i in range(0, len(odd_numbers), 2):
            # SWAP
            odd_numbers[i], odd_numbers[i + 1] = odd_numbers[i + 1], odd_numbers[i]
    # STEP C
    elif remainder == 2:
        odd_numbers[0], odd_numbers[2] = odd_numbers[2], odd_numbers[0]
        # move 5 to the last
        num = odd_numbers.pop(4)
        odd_numbers.append(num)
    # STEP D
    elif remainder in (3, 9):
        one, three = odd_numbers[0], odd_numbers[2]
        odd_numbers.pop(0)
        odd_numbers.pop(1)
        # move to last
        odd_numbers.append(one)
        odd_numbers.append(three)

    # STEP E Append the even numbers from 2 to n in order
    even_numbers = [i for i in range(2, n + 1, 2)]
    final_arrangement = odd_numbers + even_numbers

    # STEP f if the remainder is 3 or 9. move 2 to the end of the list
    if remainder in (3, 9):
        two = final_arrangement.pop(1)
        final_arrangement.append(two)

    return final_arrangement


# TEST
if __name__ == '__main__':
    print('15 Queens solution is: ', get_solution(15))
    print('8 Queens solution is: ', get_solution(8))
    print('25 Queens solution is: ', get_solution(25))

=========

Add a comment
Know the answer?
Add Answer to:
Following are the steps (algorithm) to obtain a solution for Queen Puzzle heuristically: a, Divide n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following algorithm that operates on a list of n integers: • Divide the n...

    Consider the following algorithm that operates on a list of n integers: • Divide the n values into n 2 pairs • Find the max of each pair. • Repeat until you have the max value of the list (a) Show the steps of the above algorithm for the list (25,19,9,8,2,26,21,26,31,26,3,14). (b) Derive and prove a tight bound on the asymptotic runtime of this algorithm (c) Assuming you just ran the above algorithm, show that you can use the result...

  • Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a...

    Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing and combining steps take a time in Θ(n n). Write a recurrence equation for the running time T (n) , and solve the equation for T (n) 2. Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing...

  • please explain/ comment 3. Eight Queens Write a program that places eight queens on a chessboard...

    please explain/ comment 3. Eight Queens Write a program that places eight queens on a chessboard (8 x 8 board) such that no queen is "attacking" another. Queens in chess can move vertically, horizontally, or diagonally. How you solve this problem is entirely up to you. You may choose to write a recursive program or an iterative (i.e., non-recursive) program. You will not be penalized/rewarded for choosing one method or another. Do what is easiest for you. 3.1. Output Below...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Discrete Mathematics 5. i) Describe an algorithm that, upon input of a number n given in...

    Discrete Mathematics 5. i) Describe an algorithm that, upon input of a number n given in base 10, outputs the digits of n in base 8, starting from the rightmost. Esrample: If you are given the number 156, the output will be 432, because (156) 10 = (234)s. ii) What will be the complexity of the algorithm? You may assume that performing the division algorithm upon two numbers to find the quotient and remainder is the basic operation. (As a...

  • (20 points) Recall the following deterministic select algorithm: (a) Divide the n elements into groups of...

    (20 points) Recall the following deterministic select algorithm: (a) Divide the n elements into groups of size 5. So n/5 groups. (b) Find the median of each group. (c) Find the median x of the n/5 medians by a recursive call to Select. (d) Call Partition with x as the pivot. (e) Make a recursive call to Select either on the smaller elements or larger elements (de- pending on the situation); if the pivot is the answer we are done....

  • in c++ Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the...

    in c++ Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide missing logic for the class Queens that will enable it to create a two-dimensional array that...

  • you will implement the A* algorithm to solve the sliding tile puzzle game. Your goal is...

    you will implement the A* algorithm to solve the sliding tile puzzle game. Your goal is to return the instructions for solving the puzzle and show the configuration after each move. A majority of the code is written, I need help computing 3 functions in the PuzzleState class from the source code I provided below (see where comments ""TODO"" are). Also is this for Artificial Intelligence Requirements You are to create a program in Python 3 that performs the following:...

  • help in design of algorithm answers with steps for study guide (2 points) Why shouldn't we...

    help in design of algorithm answers with steps for study guide (2 points) Why shouldn't we measure time efficiency based on the number of seconds or milliseconds it takes the algorithm 1. to run? is the number of times the most important operation of the (2 points) The 2. algorithm occ Ccurs (3 points) Find the binary representation of the following numbers: 3. BINARY REPRESENTATION (in bits) NUMBER 777 14 684,739 4. (8 points) Write the input size metric and...

  • 8. (1) Implement the minimum subsequence sum using divide-and-conquer. (30 points) (2) For the array =[4-3...

    8. (1) Implement the minimum subsequence sum using divide-and-conquer. (30 points) (2) For the array =[4-3 5-2-1 2 6-2, you should provide the solution using the minimum subsequence sum like the example in class. Test the sample for your code. (3) Obtain the T(n) expression for the above algorithm

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT