موضوع: سورس کد n-queen با متلب
-
2016/08/22, 01:15 #1
سورس کد n-queen با متلب
با سلام و احترام میخوام برای کد n-queen در متلب طراحی هم انجام بدم آیا امکان پذیر هست؟ (یعنی اینکه خروجی رو که داد یک صفحه n*n ایجاد کند و وزیرها را در جاهای مشخص شده قراردهد)
-
2016/08/22, 21:46 #2
سلام کد زیر رو ببنید ممکن هست کارتون رو راه بندازه
این قطعه کد هم در نظر بگیرید
کد:clear all clc tic; %start the clock, want to see how long this will take count = 0; n = 8; cols = 1:n; col_perms = perms(cols); %find all permutations of 1:n for i = 1:length(col_perms) % for each permutation, do: this_col = col_perms(i,:); % get the permutation for j = 1:n % for 1:n, check for conflicts on the diagonals upper(j) = this_col(j) + j; lower(j) = this_col(j) – j; end if and(length(unique(upper)) == n,length(unique(lower))==n) % if there are no conflicts we’ve found a partition % let’s count it count = count+1; end end disp([‘Found ‘ num2str(count) ‘ arrangements of queens.’… ‘ This took ‘ num2str(toc) ‘ seconds.’]);
آموزش نرم افزار ارناسیستم کارخانه تولید خودروسیستم بیمارستان تخصصیسیستم دانشکده مهندسی -
1