I'm new user for freemat and I learning to use freemat
freemat version 4.2 b
file name queen.m
---------------------------------------------------------------------------------------
function queen
tic
clc;
counter = 0;
n = 8;
board = zeros(1,n);
[board,counter] = back(1, board,counter);
fprintf('Solution count: %d\n',counter);
toc
%%
function value = isSolution(board)
for i = 1:length(board)
for j = (i+1): length(board)
if abs(board(i) - board(j)) == abs(i-j)
value = false;
return;
end
end
end
value = true;
%%
function [board,counter] = back(depth, board,counter)
if (depth == length(board)+1) && isSolution(board)
counter = counter + 1;
disp(board);
end
if ( depth <= length(board))
for i = 1:length(board)
if ~any(board==i)
board(1,depth) = i;
[~,counter] = back(depth+1, board,counter);
end
end
end
--------------------------------------------------------------------------------------------------------------------
Error: unrecognized token at line number: 31 of file D:/Program File/FreeMat/queen.m
board(1,depth) = i;
[~,counter] = back(depth+1, board,counter);
^
question
1. in freemat What use for (~)
2. how can i use function (Error: only scripts can be source-ed, not functions)
sorry for my english.
thank you
Error: unrecognized token at line number: 31 of file D:/Program File/FreeMat/queen.m
board(1,depth) = i;
[~,counter] = back(depth+1, board,counter);
^
I can not solve it. in matlab and octave can execute successfully.