views:

323

answers:

2

using nQueens problem how to translate this algorithm to java code

 function MIN-CONFLICTS(csp,max_steps) returns a solution or failure
   inputs: csp, a constraint satisfaction problem
           max_steps,the number of steps allowed before giving up
   current<-- an initial assignment for csp
   for i=1 to max_steps do
       if current is a solution of csp then return current
       var<-- a randomly chosen, conflicted variable from VARIABLES[csp]
       value<-- the value v for var that minimizes CONFLICTS(var,v,current,csp)
       set var = value in current
 return failure
+4  A: 

By going to your TA's office hours or asking your professor for help.

David Kanarek
many thanks, how i forget that.
ehab refaat
A: 

the problem i faced is that how to sum the diagonals of a specific element for example

0 0 1 0 0 
1 0 0 0 1 
0 0[1]0 0 
0 0 0 0 1 
0 1 0 0 0 

i want to write a method to sum this element diagonals

ehab refaat
I don't quite understand what you mean by sum the diagonals of an element. Could you clarify?
David Kanarek
Store the elements in 2D array, sum all elements in single loop'sum= sum+myArray[i][i]'
Ravi Gupta
i mean that:suppose i want to sum diagonals of element in [] \: [0,0][1,1][2,2][3,3][4,4] /: [0,4][1,3][2,2][3,1][4,0] this for any element i want
ehab refaat