Recursion not going back looking for different path
I am trying to write a backtracking algorithm for harmonious graph coloring (no adjacent colors can be the same, and also each pair of colors can appear only once). This is the backtracking function:
void Graph::colorBacktrack(int a, int b) {
print();
for (int i = 1; i <= colors; i++) //assigning colors until match
{
elems[a][b] = i; //color
if (check(a, b)) break; //if it's alright break
if (i == colors) // if all the colors have been used 
return; //return one stack back and look again
}
int nextA;
int nextB = b;
if (a < size  1 ) nextA = a + 1;
else {
nextA = 0;
nextB = b + 1;
}
if (a == size && b == size  1) //when array is complete  cout finished
{
cout << endl << endl << "Finished" << endl << endl;
}
colorBacktrack(nextA, nextB); //go to next node when everything is fine
}
checking is working properly and all the other things. The problem is that the output is wrong  at the end it shows something like this:
1 4 2 6
2 5 7 8
3 6 4 8 < this is wrong
1 7 3 0 < this is also wrong
So when it cannot find a solution in current tree it just ends everything instead of going up. Why is it happening?
See also questions close to this topic

const correct composition using std::unique_ptr / std::shared_ptr
Currently I am wondering how to correctly use an
std::unique_ptr
as a member variable regarding const correctness.The following example allows to change the content owned by
my_foo
despite is being const:#include <iostream> #include <memory> struct foo { foo() : value_ptr_(std::make_unique<int>(3)) {} void increment() const { ++(*value_ptr_); } int get_value() const { return *value_ptr_; } std::unique_ptr<int> value_ptr_; }; int main() { const foo my_foo; std::cout << my_foo.get_value() << std::endl; my_foo.increment(); // But my_foo is const! std::cout << my_foo.get_value() << std::endl; }
Replacing
std::make_unique<T>
withstd::make_unique<const T>
seems like a good solution at first glance. However this disallows to change the content ofmy_foo
even if it is nonconst:#include <iostream> #include <memory> struct foo { foo() : value_ptr_(std::make_unique<int>(3)) {} void increment() { ++(*value_ptr_); } int get_value() const { return *value_ptr_; } std::unique_ptr<const int> value_ptr_; }; int main() { foo my_foo; std::cout << my_foo.get_value() << std::endl; my_foo.increment(); // compiler error std::cout << my_foo.get_value() << std::endl; }
Having a pointer to an int like in this minimal example is of course not very meaningful, but in real code the
unique_ptr
could hold a pointer to a base class of something polymorphic, i.e. an object we would not be able to simply store by value.So how can this situation be handled better?

Segmentation fault when calling member function using std::function
I dont have much experience with std::bind or std::function so there may be a lot of basic errors.
I am trying to store a function as a member of class foo which stores another member function from another class. The only things known are function parameters.
Class foo (example)
class foo{ private: someMembers; public std::function<void(task*)> task_routine; //temporary. Will be encapsulated after its working like this someMoreMembersConstructorsetc; }
Here is a example for another class:
class anotherClass{ private: void task_routine_default(task*){ someStuffThatUsesThis>; } private: anotherClass(someParameters){ . . . foo f1(); f1.task_routine = std::bind(&anotherClass::task_routine_default,&*this,std::placeholders::_1); . . . } }
there is also another class. All it does it keep the class foo and calls the function stored...
What exactly is the problem here?
EDIT
The segfault only happens when I let the caller pass the class foo as an argument.
Here is an exerpt directly from my actual program, at the location of the problem:
void *update(void* rail){ while(((*(railer*)rail).status){ (*(railer*)rail).busy = true; for(int i=0;i<taskManager::tasks.size();i++){ taskManager::tasks.at(i)>task_routine(taskManager::tasks.at(i)); } (*(railer*)rail).busy = false; } }
if I pass NULL instead of taskManager::tasks.at(i) the function runs successfully and I can access this>. However I need the parameter for complete execution (contains some variables I need) so leaving it out is NOT an option. Why is this happening??

Check Wireless State in Qt
I want to connect some signal to my slot to notify me when wireless connection disconnect or connect in Qt base on documentation I Use
onlineStateChanged
signal that define inQNetworkConfigurationManager
class base on this link linkmy code does not work on windows ( not test on Linux) when turning off or turn on wifi but sometimes when turn of my Bluetooth or Ethernet signal trigger my simple code is
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager(); ChangeEvent *myhandler = new ChangeEvent (); QObject::connect(ncm, SIGNAL(onlineStateChanged(bool)), myhandler, SLOT(myslot(bool)));

Porting (simplytyped) lambda calculus term saturation proof from Coq to Agda
I'm trying to port
msubst_R
from Software Foundations, vol. 2 to Agda. I'm trying to avoid a lot of busywork by using a typed representation for terms. Below is my port of everything up tomsubst_R
; I think everything is fine below but it's needed for the problematic part.open import Data.Nat open import Relation.Binary.PropositionalEquality hiding (subst) open import Data.Empty open import Data.Unit open import Relation.Binary open import Data.Star open import Level renaming (zero to lzero) open import Data.Product open import Function.Equivalence hiding (sym) open import Function.Equality using (_⟨$⟩_) data Ty : Set where fun : Ty → Ty → Ty infixl 21 _▷_ data Ctx : Set where [] : Ctx _▷_ : Ctx → Ty → Ctx data Var (t : Ty) : Ctx → Set where vz : ∀ {Γ} → Var t (Γ ▷ t) vs : ∀ {Γ u} → Var t Γ → Var t (Γ ▷ u) data _⊆_ : Ctx → Ctx → Set where done : ∀ {Δ} → [] ⊆ Δ keep : ∀ {Γ Δ a} → Γ ⊆ Δ → Γ ▷ a ⊆ Δ ▷ a drop : ∀ {Γ Δ a} → Γ ⊆ Δ → Γ ⊆ Δ ▷ a ⊆refl : ∀ {Γ} → Γ ⊆ Γ ⊆refl {[]} = done ⊆refl {Γ ▷ _} = keep ⊆refl data Tm (Γ : Ctx) : Ty → Set where var : ∀ {t} → Var t Γ → Tm Γ t lam : ∀ t {u} → (e : Tm (Γ ▷ t) u) → Tm Γ (fun t u) app : ∀ {u t} → (f : Tm Γ (fun u t)) → (e : Tm Γ u) → Tm Γ t wkvar : ∀ {Γ Δ t} → Γ ⊆ Δ → Var t Γ → Var t Δ wkvar done () wkvar (keep Γ⊆Δ) vz = vz wkvar (keep Γ⊆Δ) (vs v) = vs (wkvar Γ⊆Δ v) wkvar (drop Γ⊆Δ) v = vs (wkvar Γ⊆Δ v) wk : ∀ {Γ Δ t} → Γ ⊆ Δ → Tm Γ t → Tm Δ t wk Γ⊆Δ (var v) = var (wkvar Γ⊆Δ v) wk Γ⊆Δ (lam t e) = lam t (wk (keep Γ⊆Δ) e) wk Γ⊆Δ (app f e) = app (wk Γ⊆Δ f) (wk Γ⊆Δ e) data _⊢⋆_ (Γ : Ctx) : Ctx → Set where [] : Γ ⊢⋆ [] _▷_ : ∀ {Δ t} → Γ ⊢⋆ Δ → Tm Γ t → Γ ⊢⋆ Δ ▷ t ⊢⋆wk : ∀ {Γ Δ} t → Γ ⊢⋆ Δ → Γ ▷ t ⊢⋆ Δ ⊢⋆wk t [] = [] ⊢⋆wk t (σ ▷ e) = (⊢⋆wk t σ) ▷ wk (drop ⊆refl) e ⊢⋆mono : ∀ {Γ Δ t} → Γ ⊢⋆ Δ → Γ ▷ t ⊢⋆ Δ ▷ t ⊢⋆mono σ = ⊢⋆wk _ σ ▷ var vz ⊢⋆refl : ∀ {Γ} → Γ ⊢⋆ Γ ⊢⋆refl {[]} = [] ⊢⋆refl {Γ ▷ _} = ⊢⋆mono ⊢⋆refl substvar : ∀ {Γ Δ t} → Γ ⊢⋆ Δ → Var t Δ → Tm Γ t substvar [] () substvar (σ ▷ x) vz = x substvar (σ ▷ x) (vs v) = substvar σ v subst : ∀ {Γ Δ t} → Γ ⊢⋆ Δ → Tm Δ t → Tm Γ t subst σ (var x) = substvar σ x subst σ (lam t e) = lam t (subst (⊢⋆mono σ) e) subst σ (app f e) = app (subst σ f) (subst σ e) data Value : {Γ : Ctx} → {t : Ty} → Tm Γ t → Set where lam : ∀ {Γ t} → ∀ u (e : Tm _ t) → Value {Γ} (lam u e) data _==>_ {Γ} : ∀ {t} → Rel (Tm Γ t) lzero where applam : ∀ {t u} (f : Tm _ t) {v : Tm _ u} → Value v → app (lam u f) v ==> subst (⊢⋆refl ▷ v) f appˡ : ∀ {t u} {f f′ : Tm Γ (fun u t)} → f ==> f′ → (e : Tm Γ u) → app f e ==> app f′ e appʳ : ∀ {t u} {f} → Value {Γ} {fun u t} f → ∀ {e e′ : Tm Γ u} → e ==> e′ → app f e ==> app f e′ _==>*_ : ∀ {Γ t} → Rel (Tm Γ t) _ _==>*_ = Star _==>_ NF : ∀ {a b} {A : Set a} → Rel A b → A → Set _ NF step x = ∄ (step x) value⇒normal : ∀ {Γ t e} → Value {Γ} {t} e → NF _==>_ e value⇒normal (lam t e) (_ , ()) Deterministic : ∀ {a b} {A : Set a} → Rel A b → Set _ Deterministic step = ∀ {x y y′} → step x y → step x y′ → y ≡ y′ deterministic : ∀ {Γ t} → Deterministic (_==>_ {Γ} {t}) deterministic (applam f _) (applam ._ _) = refl deterministic (applam f v) (appˡ () _) deterministic (applam f v) (appʳ f′ e) = ⊥elim (value⇒normal v (, e)) deterministic (appˡ () e) (applam f v) deterministic (appˡ f e) (appˡ f′ ._) = cong _ (deterministic f f′) deterministic (appˡ f e) (appʳ f′ _) = ⊥elim (value⇒normal f′ (, f)) deterministic (appʳ f e) (applam f′ v) = ⊥elim (value⇒normal v (, e)) deterministic (appʳ f e) (appˡ f′ _) = ⊥elim (value⇒normal f (, f′)) deterministic (appʳ f e) (appʳ f′ e′) = cong _ (deterministic e e′) Halts : ∀ {Γ t} → Tm Γ t → Set Halts e = ∃ λ e′ → e ==>* e′ × Value e′ value⇒halts : ∀ {Γ t e} → Value {Γ} {t} e → Halts e value⇒halts {e = e} v = e , ε , v   This would not be strictly positive!  data Saturated : ∀ {Γ t} → Tm Γ t → Set where  fun : ∀ {t u} {f : Tm [] (fun t u)} → Halts f → (∀ {e} → Saturated e → Saturated (app f e)) → Saturated f mutual Saturated : ∀ {t} → Tm [] t → Set Saturated e = Halts e × Saturated′ _ e Saturated′ : ∀ t → Tm [] t → Set Saturated′ (fun t u) f = ∀ {e} → Saturated e → Saturated (app f e) saturated⇒halts : ∀ {t e} → Saturated {t} e → Halts e saturated⇒halts = proj₁ step‿preserves‿halting : ∀ {Γ t} {e e′ : Tm Γ t} → e ==> e′ → Halts e ⇔ Halts e′ step‿preserves‿halting {e = e} {e′ = e′} step = equivalence fwd bwd where fwd : Halts e → Halts e′ fwd (e″ , ε , v) = ⊥elim (value⇒normal v (, step)) fwd (e″ , s ◅ steps , v) rewrite deterministic step s = e″ , steps , v bwd : Halts e′ → Halts e bwd (e″ , steps , v) = e″ , step ◅ steps , v step‿preserves‿saturated : ∀ {t} {e e′ : Tm _ t} → e ==> e′ → Saturated e ⇔ Saturated e′ step‿preserves‿saturated step = equivalence (fwd step) (bwd step) where fwd : ∀ {t} {e e′ : Tm _ t} → e ==> e′ → Saturated e → Saturated e′ fwd {fun s t} step (halts , sat) = Equivalence.to (step‿preserves‿halting step) ⟨$⟩ halts , λ e → fwd (appˡ step _) (sat e) bwd : ∀ {t} {e e′ : Tm _ t} → e ==> e′ → Saturated e′ → Saturated e bwd {fun s t} step (halts , sat) = Equivalence.from (step‿preserves‿halting step) ⟨$⟩ halts , λ e → bwd (appˡ step _) (sat e) step*‿preserves‿saturated : ∀ {t} {e e′ : Tm _ t} → e ==>* e′ → Saturated e ⇔ Saturated e′ step*‿preserves‿saturated ε = id step*‿preserves‿saturated (step ◅ steps) = step*‿preserves‿saturated steps ∘ step‿preserves‿saturated step
Note that I have removed the
bool
andpair
types since they are not necessary to show my problem.The problem, then, is with
msubst_R
(which I callsaturate
below):data Instantiation : ∀ {Γ} → [] ⊢⋆ Γ → Set where [] : Instantiation [] _▷_ : ∀ {Γ t σ} → Instantiation {Γ} σ → ∀ {e} → Value {_} {t} e × Saturated e → Instantiation (σ ▷ e) saturatevar : ∀ {Γ σ} → Instantiation σ → ∀ {t} (x : Var t Γ) → Saturated (substvar σ x) saturatevar (_ ▷ (_ , sat)) vz = sat saturatevar (env ▷ _) (vs x) = saturatevar env x applam* : ∀ {Γ t} {e e′ : Tm Γ t} → e ==>* e′ → Value e′ → ∀ {u} (f : Tm _ u) → app (lam t f) e ==>* subst (⊢⋆refl ▷ e′) f applam* steps v f = gmap _ (appʳ (lam _ _)) steps ◅◅ applam f v ◅ ε saturate : ∀ {Γ σ} → Instantiation σ → ∀ {t} → (e : Tm Γ t) → Saturated (subst σ e) saturate env (var x) = saturatevar env x saturate env (lam u f) = value⇒halts (lam u _) , satf where f′ = subst _ f satf : ∀ {e : Tm _ u} → Saturated e → Saturated (app (lam u f′) e) satf sat@((e′ , steps , v) , _) = Equivalence.from (step*‿preserves‿saturated (applam* steps v f′)) ⟨$⟩ saturate ([] ▷ (v , Equivalence.to (step*‿preserves‿saturated steps) ⟨$⟩ sat)) f′ saturate env (app f e) with saturate env f  saturate env e saturate env (app f e)  _ , satf  sate = satf sate
saturate
doesn't pass the termination checker, because in thelam
case,satf
recurses intosaturate
onf′
, which isn't necessarily smaller thanlam u f
; and[] ▷ e′
is also not necessarily smaller thanσ
.Another way of looking at why
saturate
doesn't terminate is to look atsaturate env (app f e)
. Here, recursing intof
and (potentially)e
will growt
, even though all the other cases either leavet
the same and shrink the term, or shrinkt
. So ifsaturate env (app f e)
didn't recurse intosaturate env f
andsaturate env e
, the recursion insaturate env (lam u f)
would not be problematic in itself.However, I think my code does the right thing for the
app f e
case (since that's the whole point of lugging around the parametric saturation proof for function types), so it should be thelam u f
case where I need a tricky way in whichf′
is smaller thanlam u f
.What am I missing?

Why is recursion not the same as dynamic programming in some cases?
I am working on dynamic programming and I came across a problem to find unique paths to reach a point 'b' from point 'a' in a m x n grid. You can only move right or down. My question is why is the following recursive approach much slower than the dynamic one described later?
Recursion:
def upaths(m,n): count = [0] upathsR(m,n, count) return count[0] def upathsR(m,n,c): # Increase count when you reach a unique path # When you reach 1 there is only one way to get to an end (optimization) if m==1 or n==1: c[0]+=1 return if m > 1: upathsR(m1,n,c) if n > 1: upathsR(m,n1,c)
Dynamic:
def upaths(m, n): count = [[1 for x in range(n)] for x in range(m)] for i in range(1, m): for j in range(1, n): count[i][j] = count[i][j1] + count[i1][j] return count[1][1]
Usually recursion has repetitive calls that can be memoized but in this case I see unique calls, Even so Recursion is much slower. Can someone explain why..
Following suggestions from the answers, it worked faster. And the calls aren't unique.
New Recursive Approach: def upaths(m,n): d = dict() return upathsR(m,n,d)
def upathsR(m,n,d): if (m,n) in d: return d[(m,n)] if m==1 or n==1: return 1 d[(m,n)] = upathsR(m1,n,d)+upathsR(m,n1,d) return d[(m,n)]

Why is the optimized fibonacci with cache described as topdown solution?
It seems that an optimized version of fibonacci algorithm is using memoization.
Example:int cache[N] = {0}; int fibonacci(int n) { if(cache[n] != 0) return cache[n]; if(n ==1  n == 2) cache[n] = 1; else cache[n] = fibonacci(n  1) + fibonacci(n  2); return cache[n]; }
This is described as a topdown solution.
But why? To findfibonacci(10)
we need to recursively call all the lower numbers until we reach to 1 and start building up. So it seems to me it is a bottomup approach.
Why is it topbottom? 
Minimum Cost Path Java calculate particular cost
I doing the "backtrack" in java.
Given a two dimensional grid, each cell of which contains integer cost which represents the cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which total cost incurred is minimum.
I made it but when I calculate the "minimal cost path" which only sum every best possible solution, the thing I try to calculate instead of sum all of the best way, I want first number on the matrix substract the next one and the result on absolute value to calculate the cost my way.
Here is the code:
import java.util.*; import java.lang.*; import java.io.*; class GFG { //return an unvisited vertix with the minimum distance. Precondition  there is at least one unvisited vertix private static int[] ChooseSource(boolean[][] visited, int[][] distances, int V){ int[] ans = new int[2]; int min_distance = Integer.MAX_VALUE; for (int r = 0; r < V; r++){ for (int c = 0; c < V; c++){ if ((visited[r][c] == false) && (distances[r][c] < min_distance)){ ans[0] = r; ans[1] = c; min_distance = distances[r][c]; } } } return ans; } /* we know that dijkstra's algoryhtm can find the cost from a source to all vertices in an undirected graph. if we look at the matrix as an undirected graph, with each vertix with (at most) 4 neighbours, we can apply it here */ private static int MinimumCostPath(int[][] costs, int n){ //initialize a DS to hold all distances int[][]distances = new int[n][n]; for (int[] d : distances) Arrays.fill(d, Integer.MAX_VALUE); int[]source = {0,0}; distances[source[0]][source[1]] = costs[source[0]][source[1]]; //initialize a DS to mark all the vertices that were visited boolean[][]visited = new boolean[n][n]; for (boolean[] b : visited) Arrays.fill(b, false); //stop if the destination was reached while (visited[n1][n1] == false){ int[] new_source = ChooseSource(visited, distances, n); int source_distance = distances[new_source[0]][new_source[1]]; /* create an array with the source's neighbours  ArrayList because the number of neighbours can very */ ArrayList<int[]> neighbours = new ArrayList<int[]>(); //go up if (new_source[0] > 0){ int[]neighbour = {new_source[0]  1, new_source[1]}; neighbours.add(neighbour); } //go down if (new_source[0] < n  1){ int[]neighbour = {new_source[0] + 1, new_source[1]}; neighbours.add(neighbour); } //go left if (new_source[1] > 0){ int[]neighbour = {new_source[0], new_source[1]  1}; neighbours.add(neighbour); } //go right if (new_source[1] < n  1){ int[]neighbour = {new_source[0], new_source[1] + 1}; neighbours.add(neighbour); } /* iterate over the unvisited neighbours of the source, relax their cost if possible */ for (int[]neighbour : neighbours){ if (visited[neighbour[0]][neighbour[1]] == false){ int current_distance = distances[neighbour[0]][neighbour[1]]; int suggested_distance = source_distance + costs[neighbour[0]][neighbour[1]]; if (suggested_distance < current_distance) distances[neighbour[0]][neighbour[1]] = suggested_distance; } } //mark the source as visited visited[new_source[0]][new_source[1]] = true; } return distances[n1][n1]; } public static void main (String[] args) { // Input the number of test cases you want to run Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // One by one run for all input test cases while (t > 0) { // Input the size of the array int n = sc.nextInt(); int[][]costs = new int[n][n]; // Input the array for (int row = 0; row < n; row++) for (int col = 0; col < n; col++) costs[row][col] = sc.nextInt(); // Compute and print result System.out.println(MinimumCostPath(costs, n)); t; } } }
And an image for better understanding
now the code does: matrix 0,0 + matrix 1,1
but I try: matrix 0,0  matrix 1,1 = Result on absolute value. then all this on every iteration(for the best path), now sum all for calculate the cost I want.
On the image it would be: 3110=21, 1013=3, the same for the rest of the path.. then sum all.
Thanks, hope someone can help me. I was doing it a month ago for self experience but sometimes it's better some help.

Generating All Subsets of a Set Using Recursive Backtracking (Python)
I'm trying to understand backtracking but I'm stuck in this problem, here's the prompt:
Given a set of distinct integers, return all possible subsets.
Example input:
[1,2,3]
Example output:
[[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
Here's my code:
def subsets(nums): res = [] backtrack(res, [], nums, 0) return res def backtrack(res, temp, nums, start): # print(temp) res.append(temp) for i in range(start, len(nums)): temp.append(nums[i]) backtrack(res, temp, nums, i + 1) temp.pop() # Backtrack
when I return
res
I get a list of empty lists of size2^(len(nums))
, which is the right size but the numbers aren't there. However printingtemp
before I dores.append(temp)
shows that temp is carrying the right output.E.g.
res = [[], [], [], [], [], [], [], []]
print statements:
[] [1] [1, 2] [1, 2, 3] [1, 3] [2] [2, 3] [3]
Why are the changes not carrying over to the
res
list?Edit 1:
This solution works, what's the difference?
def subsets(nums): res = [] backtrack(res, [], nums, 0) return res def backtrack(res, temp, nums, start): # print(temp) res.append(temp) for i in range(start, len(nums)): backtrack(res, temp + [nums[i]], nums, i + 1)

BackTracking Suduko in java
**
I implemented Sudoku backtracking in Java by taking reference from geeks for geeks but I am unable to get output.Can I know where I am doing wrong.? http://www.geeksforgeeks.org/backtrackingset7suduku/
**
Algorithm: Find row, col of an unassigned cell If there is none, return true For digits from 1 to 9
a) If there is no conflict for digit at row, col assign digit to row, col and recursively try fill in rest of grid
b) If recursion successful, return true
c) Else, remove digit and try another If all digits have been tried and nothing worked, return false
package a; import java.util.*; class Gra { static public boolean allover(int[][] arr,ArrayList<Integer> a){ for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ if(arr[i][j]==0){ a.set(0, i); a.set(1, j); return true; } } } return false; } static public boolean issafe(int[][] arr,int col,int row,int value){ return !UsedInRow(arr, row, value) && !UsedInCol(arr, col,value) && !UsedInBox(arr, row  row%3 , col  col%3, value); } static boolean UsedInRow(int grid[][], int row, int num) { for (int col = 0; col < 9; col++) if (grid[row][col] == num) return true; return false; } static boolean UsedInCol(int grid[][], int col, int num) { for (int row = 0; row < 9; row++) if (grid[row][col] == num) return true; return false; } static boolean UsedInBox(int[][] grid, int boxStartRow, int boxStartCol, int num) { for (int row = 0; row < 3; row++) for (int col = 0; col < 3; col++) if (grid[row+boxStartRow][col+boxStartCol] == num) return true; return false; } public static boolean solve(int[][] arr){ ArrayList<Integer> a = new ArrayList<>(); a.add(0); a.add(0); if(!allover(arr,a)){ return true; } int row=a.get(0); int col=a.get(1); for(int i=1;i<=9;i++){ if(issafe(arr,row,col,i)){ arr[row][col]=i; if(solve(arr)){ return true; } arr[row][col]=0; } } return false; } static void printGrid(int grid[][]) { for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) System.out.print(grid[row][col]); System.out.println(""); } } public static void main(String args[]) { Gra op = new Gra(); // 0 means unassigned cells int grid[][] = {{3, 0, 6, 5, 0, 8, 4, 0, 0}, {5, 2, 0, 0, 0, 0, 0, 0, 0}, {0, 8, 7, 0, 0, 0, 0, 3, 1}, {0, 0, 3, 0, 1, 0, 0, 8, 0}, {9, 0, 0, 8, 6, 3, 0, 0, 5}, {0, 5, 0, 0, 9, 0, 6, 0, 0}, {1, 3, 0, 0, 0, 0, 2, 5, 0}, {0, 0, 0, 0, 0, 0, 0, 7, 4}, {0, 0, 5, 2, 0, 6, 3, 0, 0}}; if (op.solve(grid) == true){ printGrid(grid); }else{ System.out.println("N"); } } }