Matlab: N queens (checking 2 table's symmetry) -
i trying make simple script can decide whether 2 chess boards similar or identical or different. have test if same size first (3x3 example) because if not shouldn't run test in first place. have vertical , horizontal flip first board , compare them second board , see if of 2 flips match second board. code have far:
function similar = symmetric_queens(b1, b2) %b1 table 1 , b2 table 2 similar= true; h1= flipud(b1); %flipping horizontal axis v1= fliplr(b1); %flipping vertical axis if b1==b2; imshow('the boards identical') %because same end if size(b1)==size(b2) %if of equal size test if horizontal flip= second board h1=b2 imshow('true') else v1=h2 %test if vertical flip = second board imshow('true') else %in these 2 codes trying check make function stop if boards arent same size size(b1)>size(b2) similar = false; return; else size(b1)<size(b2) similar = false; return; end end
i think there lots of mistakes causing code not wrk, highly appreciated. sorry if didn't post right or if did wrong first time posting in here.
thanks in advance!
little bit organized code think same thing -
function similar = symmetric_queens(b1, b2) %b1 table 1 , b2 table 2 %%// check equal sizes if ~isequal(size(b1),size(b2)) similar = false; return; end if isequal(b2,b1) %%// check perfect match disp('the boards identical'); similar = true; %%// return - similar value when identical? assumed - true elseif isequal(b2,fliplr(b1)) || isequal(b2,flipud(b1)) %%// check horizontal , vertical flip disp('the boards similar'); similar = true; else similar = false; end return;
note: wasn't sure why have used imshow
. maybe meant displaying text? that's code do.
Comments
Post a Comment