% this program places N queenson the NxN board % a/ randomly % b/ one queen in each column % c/ onequeen in each column and one queen in each row % and checks the number of attacks. % It places the queens repeatedly until there is no attack. % This is a brute force method for solving the N-queen problem. % This program additionally calculates the average number of attmepts % in 100 tries. clear clc N = 4; numAttacks = 1; attempt_counter = 0; avg_attempts = 0; for i = 1 : 100 while numAttacks ~= 0 % A = place_N_queens_random(N); A = place_N_queens_cols(N); % A = place_N_queens_cols_rows(N); numAttacks = find_attacks_gen(A, N); attempt_counter = attempt_counter + 1; end avg_attempts = attempt_counter / i; numAttacks = 1; end attempt_counter A