Question

In: Computer Science

mips code for n queen problem

mips code for n queen problem

Solutions

Expert Solution

class queen position

{

int row;

int col;

int n

public queen position(int row, int col) {

super( );

this.row = row;

this.col = col;

this.n = n;

}

import java.io.PrintWriter;

import java.util.Arrays;

import java.util.Scanner;

public class NQueenProblem {

    public static PrintWriter out = new PrintWriter(System.out);

    public static QueenPosition[] p;

    public static void main(String[] args) {

        System.out.println("Enter Number of Queens");

        Scanner s = new Scanner(System.in);

        int n = s.nextInt();

        p = new QueenPosition[n];

        if(getSolution(n,0))

        {

            int[][] result = new int[n][n];

            Arrays.stream(p).forEach(po->result[po.row][po.col]=1);

            out.println("Display using Stream API \n-----------------------");

            Arrays.stream(result)

            .forEach(rw -> {

                Arrays.stream(rw)

                .forEach(rw1-> out.print(rw1 + " "));

                out.println();

            });

             

            out.println("\n\nDisplay using normal For loop \n---------------------------");

            for(int i=0;i < n;i++)

            {

                for(int j=0;j < n;j++)

                {

                    out.print(result[i][j] + " ");

                }

            out.println();

            }

        }

        else

        {

            out.println("Solution not available.");

}

        out.flush();

    }

    public static boolean getSolution(int n, int row)

    {

    }  

}


Related Solutions

Write MIPS code for finding the (estimated) square-root of a number N, by using the following...
Write MIPS code for finding the (estimated) square-root of a number N, by using the following pseudo-code: sqrt = N; repeat 10 times { sqrt = (sqrt + N/sqrt)/2; } The number N is entered by the user and the answer is displayed on the screen as (for example): The square root of 121 is 11. Write MIPS code for finding the distance between two points [x1,y1] and [x2,y2]. The formula for the distance is: z = ?(x2 − x1)2...
1. Write MIPS assembly code to sum “n” positive integers. Forexample, n=5, read 5 numbers...
1. Write MIPS assembly code to sum “n” positive integers. For example, n=5, read 5 numbers in memory (“.data” section) and add them together. 2. Write MIPS assembly code to calculate N-factorial. Read n from the memory. (Hint: use “.data” to define the content in a memory location)
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”;...
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”; cin >> $s0; cout << “\n Please input a number for $s1”; cin >> $s1; cout << “\n Please input a number for $s2”; cin >> $s2; $t0 = $s0 / 8 - 2 * $s1 + $s2; cout << “\n the Value of the expression “$s0 / 8 - 2 * $s1 + $s2” is ”; cout >> $t0; return;
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered...
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered by the user in a 300-byte buffer. The function must return the actual size of the entered text in number of bytes. The text could contain lines, that is to say that the symbol '\ n' could be present. The end of reading is defined by both consecutive '\ n' '\ n' symbols. 2) Code in MIPS a function that helps identify if the...
The n th Triangle Problem Write a code for finding the n th triangle number of...
The n th Triangle Problem Write a code for finding the n th triangle number of triangle sequences: 1, 3, 6, 10, ..., n. That is, your code should accept an integer number, which indicates the triangle levels, and returns how many dots we need to form a triangle with respect to the given level. For example, consider the Fig 1. For n = 3 (can be also written as T3), your code should returns 6. Provide a single program...
Need this 8 queen code with same exact solution without goto. Need to keep the code...
Need this 8 queen code with same exact solution without goto. Need to keep the code as similar as possible. #include <iostream> #include <cmath> using namespace std; int main(){ int q[8], c = 0, i, j,count=0; q[0] = 0; //first queen top corner nc: c++; if(c == 8 ) goto print; q[c] = -1; nr: q[c]++; if(q[c] == 8) goto backtrack; for(i= 0; i < c; i++) { if((q[i] == q[c])||(c - i == abs(q[c] - q[i]))) goto nr; }...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT