Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
bartleby
Concept explainers
Question
TRANSLATE TO PYTHON
import java.util.*;
public class queen {
finalprivateint [][] map = newint[8][8];
finalprivateint [][] testMap = newint[8][8];
privateintheuristic = 0;
privateintqueenLocs = 0;
privateintrestarts = 0;
privateintmoves = 0;
privateintneighbors = 8;
publicqueen( ){ //initializes the map
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
map[i][j] = 0;
}
}
}
publicvoidrandomizeMap( ){ //randomizes the map
Randomrand = newRandom( );
intnum;
while(queenLocs < 8){
for(inti = 0; i < 8; i++){
map[rand.nextInt(7)][i] = 1;
queenLocs++;
}
}
heuristic = heuristic(map);
}
//***************************Heuristic****************************//
publicbooleanfindRowEx(int [][] test, inta){ //determines row conflicts
booleanexFound = false;
intcount = 0;
for(inti = 0; i < 8; i++){
if(test[i][a] == 1){
count++;
}
}
if(count > 1){
exFound = true;
}
returnexFound;
}
publicbooleanfindColEx(int [][] test, intj){ //determines column conflicts
booleanexFound = false;
intcount = 0;
for(inti = 0; i < 8; i++){
if(test[j][i] == 1){
count++;
}
}
if(count > 1){
exFound = true;
}
returnexFound;
}
publicbooleanfindDiaEx(int [][] test, inta, intb){//determines diagonal conflicts
booleandiaFound = false;
for(inti = 1; i < 8; i++){
if(diaFound){
break;
}
if((a+i < 8)&&(b+i < 8)){
if(test[a+i][b+i] == 1){
diaFound = true;
}
}
if((a-i >= 0)&&(b-i >= 0)){
if(test[a-i][b-i] == 1){
diaFound = true;
}
}
if((a+i < 8)&&(b-i >= 0)){
if(test[a+i][b-i] == 1){
diaFound = true;
}
}
if((a-i >= 0)&&(b+i < 8)){
if(test[a-i][b+i] == 1){
diaFound = true;
}
}
}
returndiaFound;
}
publicintheuristic(int [][] test){//Counts the number of queens in conflict
intcount = 0;
booleanrowEx;
booleancolEx;
booleandiaEx;
for(inti = 0; i < 8; i++){
for(intj= 0; j < 8; j++){
if(test[i][j] == 1){
rowEx = findRowEx(test, j);
colEx = findColEx(test, i);
diaEx = findDiaEx(test, i, j);
if(rowEx || colEx || diaEx){
count++;
}
}
}
}
returncount;
}
//***********************Move Queen***********************//
publicvoidmoveQueen( ){ //moves a queen and determines whether to continue to a new state or restart or to summarize solution
int[][] hArray = newint[8][8];
intcolCount;
intminCol;
intminRow;
intprevColQueen = 0;
while(true){
colCount = 0;
for(inti = 0; i < 8; i++){
System.arraycopy(map[i], 0, testMap[i], 0, 8);
}
while(colCount < 8){
for(inti = 0; i < 8;i++){
testMap[i][colCount] = 0;
}
for(inti = 0; i < 8; i++){
if(map[i][colCount] == 1){
prevColQueen = i;
}
testMap[i][colCount] = 1;
hArray[i][colCount] = heuristic(testMap);
testMap[i][colCount] = 0;
}
testMap[prevColQueen][colCount] = 1;
colCount++;
}
if(determineRestart(hArray)){
queenLocs = 0;
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
map[i][j] = 0;
}
}
randomizeMap( );
System.out.println("RESTART");
restarts++;
}
minCol = findMinCol(hArray);
minRow = findMinRow(hArray);
for(inti = 0; i < 8; i++){
map[i][minCol] = 0;
}
map[minRow][minCol] = 1;
moves++;
heuristic = heuristic(map);
if(heuristic(map) == 0){
System.out.println("\nCurrent State");
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
System.out.print(map[i][j] + " ");
}
System.out.print("\n");
}
System.out.println("Solution Found!");
System.out.println("State changes: " + moves);
System.out.println("Restarts: " + restarts);
break;
}
System.out.println("\n");
System.out.println("Current h: " + heuristic);
System.out.println("Current State");
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
System.out.print(map[i][j] + " ");
}
System.out.print("\n");
}
System.out.println("Neighbors found with lower h: " + neighbors);
System.out.println("Setting new current State");
}
}
publicintfindMinCol(int[][] test){ //finds column of minimum neighbor state
intminCol = 8;
intminVal = 8;
intcount = 0;
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
if(test[i][j] < minVal){
minVal = test[i][j];
minCol = j;
}
if(test[i][j] < heuristic){
count++;
}
}
}
neighbors = count;
returnminCol;
}
publicintfindMinRow(int[][] test){ //finds row of minimum neighbor state
intminRow = 8;
intminVal = 8;
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
if(test[i][j] < minVal){
minVal = test[i][j];
minRow = i;
}
}
}
returnminRow;
}
publicbooleandetermineRestart(int [][] test){// determines whether restart is necessary
intminVal = 8;
booleanrestart = false;
for(inti = 0; i < 8; i++){
for(intj = 0; j < 8; j++){
if(test[i][j] < minVal){
minVal = test[i][j];
}
}
}
if(neighbors == 0){
restart = true;
}
returnrestart;
}
/************************* Main **********************/
publicstaticvoidmain(String[] args) {// creates object, creates initial random map, then initiates state change
queenone = newqueen();
one.randomizeMap();
one.moveQueen();
}
}
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
Step by stepSolved in 2 steps
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java Program ASAP Please modify Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); in the program so it reads the two text files and passes the test cases. Down below is a working code. Also dont add any import libraries in the program just modify the rest of the code so it passes the test cases. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class MorseCodeConverter { public static void main(String[] args) { Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); Scanner scanner = new Scanner(System.in); System.out.print("Please enter the file name or type QUIT to exit:\n"); do { String fileName = scanner.nextLine().trim(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { String text =...arrow_forwardimport 'dart:io';import 'module.dart';List<Module> modules = [];void main() {int? choice = 1;while (choice != 5) {choice = menu();if (choice != null && choice >= 1 && choice <= 5) {switch (choice) {case 1:createFromExisting();break;case 2:printModuleData();break;case 3:changeWeights();break;case 4:printAverageOfClass();break;}} else {print('Invalid choice, please choose again');choice = -1;}}print('Good bye!');}void createFromExisting() {//30 marks//This method retrieves the data from the TPG316C.csv file to create a new Module////Steps://1. Ask the user to enter a name for the new module//2. Read the name//3. Ask the user to enter the name of the file to read module data from (we will use TPG316C.csv)//4. Read the name of the file//5. Read the lines from the file into a List<String>//6. Create a new Module instance with empty fields, except for the name of the Module//7. Use the first element in the List<String> created in step 5 to extract the...arrow_forwardUSING THE FOLLOWING METHOD SWAP CODE: import java.util.*; class ListIndexOutOfBoundsException extends IndexOutOfBoundsException { public ListIndexOutOfBoundsException(String s) { super(s); } } class ListUtil { public static int maxValue(List<Integer> aList) { if(aList == null || aList.size() == 0) { throw new IllegalArgumentException("List cannot be null or empty"); } int max = aList.get(0); for(int i = 1; i < aList.size(); i++) { if(aList.get(i) > max) { max = aList.get(i); } } return max; } public static void swap(List<Integer> aList, int i, int j) throws ListIndexOutOfBoundsException { if(aList == null) { throw new IllegalArgumentException("List cannot be null"); } if(i < 0 || i >= aList.size() || j < 0 || j >= aList.size()) { throw new ListIndexOutOfBoundsException("Index out...arrow_forward
- #include <iostream>#include <cstdlib>using namespace std; class IntNode {public: IntNode(int dataInit = 0, IntNode* nextLoc = nullptr); void InsertAfter(IntNode* nodeLoc); IntNode* GetNext(); void PrintNodeData(); int GetDataVal();private: int dataVal; IntNode* nextNodePtr;}; // ConstructorIntNode::IntNode(int dataInit, IntNode* nextLoc) { this->dataVal = dataInit; this->nextNodePtr = nextLoc;} /* Insert node after this node. * Before: this -- next * After: this -- node -- next */void IntNode::InsertAfter(IntNode* nodeLoc) { IntNode* tmpNext = nullptr; tmpNext = this->nextNodePtr; // Remember next this->nextNodePtr = nodeLoc; // this -- node -- ? nodeLoc->nextNodePtr = tmpNext; // this -- node -- next} // Print dataValvoid IntNode::PrintNodeData() { cout << this->dataVal << endl;} // Grab location pointed by nextNodePtrIntNode* IntNode::GetNext() { return this->nextNodePtr;} int IntNode::GetDataVal() {...arrow_forwardplease fix code to match "enter patients name in lbs" thank you import java.util.LinkedList;import java.util.Queue;import java.util.Scanner; interface Patient { public String displayBMICategory(double bmi); public String displayInsuranceCategory(double bmi);} public class BMI implements Patient { public static void main(String[] args) { /* * local variable for saving the patient information */ double weight = 0; String birthDate = "", name = ""; int height = 0; Scanner scan = new Scanner(System.in); String cont = ""; Queue<String> patients = new LinkedList<>(); // do while loop for keep running program till user not entered q do { System.out.print("Press Y for continue (Press q for exit!) "); cont = scan.nextLine(); if (cont.equalsIgnoreCase("q")) { System.out.println("Thank you for using BMI calculator"); break;...arrow_forwardIn C++.arrow_forward
- PROBLEM STATEMENT: In this problem you will need to insert 5 at the frontof the provided ArrayList and return the list. import java.util.ArrayList;public class InsertElementArrayList{public static ArrayList<Integer> solution(ArrayList<Integer> list){// ↓↓↓↓ your code goes here ↓↓↓↓return new ArrayList<>(); Can you help me with this question The Language is Javaarrow_forwardFor any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, 1 #include 2 3 int main(void) { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; 4 6 7 8 scanf("%d", &keysList[0]); scanf ("%d", &keysList[1]); scanf("%d", &keysList[2]); scanf("%d", &keysList[3]); 10 11 12 13 scanf ("%d", &itemsList[0]); scanf ("%d", &itemsList[1]); scanf("%d", &itemsList[2]); scanf ("%d", &itemsList[3]); 14 15 16 17 18 19 /* Your code goes here */ 20 21 printf("\n"); 22 23 return 0; 24 }arrow_forwardJava/Data Structures: The Java Class Library implementation of the interface list return null when an index is out of range. True or Falsearrow_forward
- using System;class TicTacToe{ static void Print(char[] board) { Console.WriteLine(); Console.WriteLine($" {board[0]} | {board[1]} | {board[2]} "); Console.WriteLine($" {board[3]} | {board[4]} | {board[5]} "); Console.WriteLine($" {board[6]} | {board[7]} | {board[8]} "); Console.WriteLine(); } static void Main(string[] args) { char[] board = new char[9]; for (int i = 0; i < 9; i = i + 1) { board[i] = ' '; } Print(board); board[4] = 'X'; Print(board); board[0] = 'O'; Print(board); board[3] = 'X'; Print(board); board[5] = 'O'; Print(board); board[6] = 'X'; Print(board); board[2] = 'O'; Print(board); }} Hello! This program is in C# could a line of code be added to ask the user if they want to be "X" or if they want to be "O"?arrow_forwardusing System; class TicTacToe { staticint player = 1; staticint choice; staticvoid Print(char[] board) { staticvoid Main(string[] args) { Console.WriteLine(); Console.WriteLine($" {board[0]} | {board[1]} | {board[2]} "); Console.WriteLine($" {board[3]} | {board[4]} | {board[5]} "); Console.WriteLine($" {board[6]} | {board[7]} | {board[8]} "); Console.WriteLine(); char[] board = newchar[9]; for (int i = 0; i < 9; i = i + 1) { board[i] = ' '; if( board[i]== 'O') Console.Write("It is your turn to place an X"); } Print(board); board[4] = 'X'; Print(board); board[0] = 'O'; Print(board); board[3] = 'X'; Print(board); board[5] = 'O'; Print(board); board[6] = 'X'; Print(board); board[2] = 'O'; Print(board); } } } Hello, what can be added to this program to make it compile? just a small simple changearrow_forwardusing System; class TicTacToe { staticvoid Print( char[] board) { Console.WriteLine(); Console.WriteLine($" {board[0]} | {board[1]} | {board[2]} "); Console.WriteLine($" {board[3]} | {board[4]} | {board[5]} "); Console.WriteLine($" {board[6]} | {board[7]} | {board[8]} "); Console.WriteLine(); } staticvoid Main(string[] args) { char[] board = newchar[9]; for (int i = 0; i < 9; i = i + 1) { board[i] = ' '; if( board[i]== 'O') Print("It is your turn to place an X"); } Print(board); board[4] = 'X'; Print(board); board[0] = 'O'; Print(board); board[3] = 'X'; Print(board); board[5] = 'O'; Print(board); board[6] = 'X'; Print(board); board[2] = 'O'; Print(board); } } Hello I can't get my code to compilearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education