#!sapphire
def size 5;
def mat makeMat(size,size);
%配置を探索する。
def search()
combination(safe?,size,directProduct(size));
%n*nの直積をつくり行列の位置とする。
def directProduct(n)
let(i,0)(j,0)(ls,[]){
for(i:=1,i<=n,i++)
for(j:=1,j<=n,j++)
ls := cons(list(i,j),ls),
ls};
%リストからn個の組み合わせを作り関数fに渡す。
def combination(f,n,ls){
def comb(n,ls,a)
if(n=0)
f(reverse(a))
else if(length(ls)=n)
f(append(reverse(a),ls))
else{
comb(n-1,cdr(ls),cons(car(ls),a)),
comb(n,cdr(ls),a)},
if(n>length(ls))
#f
else
comb(n,ls,[])
};
%距離を記憶する場所
def lengthLs [];
%直積でつくった位置の行列の要素を1とする。他は0。
def writeBoard(ls){
initBoard(),
writeBoard1(ls)
};
def writeBoard1(ls)
if(null?(ls))
#t
else
let(i,caar(ls))(j,cadar(ls)){
mat[i,j] := 1,
writeBoard1(cdr(ls))
};
%行列の初期化
def initBoard()
let(i,0)(j,0)
for(i:=1,i<=size,i++)
for(j:=1,j<=size,j++)
mat[i,j] := 0;
%その配置はセーフか?セーフなら表示する。
def safe?(ls){
lengthLs := [],
writeBoard(ls),
catch tag
let(i,0)(j,0){
for(i:=1,i<=size,i++)
for(j:=1,j<=size,j++)
when(mat[i,j]=1 && not(safe1?(i,j)))
throw tag #f,
print(ls)}};
def safe1?(x,y)
catch tag{
let(i,0)(j,0)
for(i:=x,i<=size,i++)
for(j:=y,j<=size,j++)
when(mat[i,j]=1 && i!=x && j!=y && check(x,y,i,j))
throw tag #f,
#t};
%距離を計算しすでにあった距離かどうかを判定する。
def check(x,y,i,j)
let(d,norm(x,y,i,j))
if(member(d,lengthLs))
#t
else{
lengthLs := cons(d,lengthLs),
#f};
%ユークリッド距離を計算
def norm(x,y,i,j)
sqrt(abs(x-i)^2+abs(y-j)^2);
IyFzYXBwaGlyZQoKZGVmIHNpemUgNTsKCmRlZiBtYXQgbWFrZU1hdChzaXplLHNpemUpOwoKJemFjee9ruOCkuaOoue0ouOBmeOCi+OAggpkZWYgc2VhcmNoKCkKICBjb21iaW5hdGlvbihzYWZlPyxzaXplLGRpcmVjdFByb2R1Y3Qoc2l6ZSkpOwoKJW4qbuOBruebtOepjeOCkuOBpOOBj+OCiuihjOWIl+OBruS9jee9ruOBqOOBmeOCi+OAggpkZWYgZGlyZWN0UHJvZHVjdChuKQogIGxldChpLDApKGosMCkobHMsW10pewogICAgZm9yKGk6PTEsaTw9bixpKyspCiAgICAgIGZvcihqOj0xLGo8PW4saisrKQogICAgICAgIGxzIDo9IGNvbnMobGlzdChpLGopLGxzKSwKICAgIGxzfTsKCiXjg6rjgrnjg4jjgYvjgonvvY7lgIvjga7ntYTjgb/lkIjjgo/jgZvjgpLkvZzjgorplqLmlbBm44Gr5rih44GZ44CCCmRlZiBjb21iaW5hdGlvbihmLG4sbHMpewogIGRlZiBjb21iKG4sbHMsYSkKICAgICAgICBpZihuPTApCiAgICAgICAgICBmKHJldmVyc2UoYSkpCiAgICAgICAgZWxzZSBpZihsZW5ndGgobHMpPW4pCiAgICAgICAgICBmKGFwcGVuZChyZXZlcnNlKGEpLGxzKSkKICAgICAgICBlbHNlewogICAgICAgICAgY29tYihuLTEsY2RyKGxzKSxjb25zKGNhcihscyksYSkpLAogICAgICAgICAgY29tYihuLGNkcihscyksYSl9LAogIGlmKG4+bGVuZ3RoKGxzKSkKICAgICNmCiAgZWxzZQogICAgY29tYihuLGxzLFtdKQp9OwoKJei3nembouOCkuiomOaGtuOBmeOCi+WgtOaJgApkZWYgbGVuZ3RoTHMgW107Cgol55u056mN44Gn44Gk44GP44Gj44Gf5L2N572u44Gu6KGM5YiX44Gu6KaB57Sg44KS77yR44Go44GZ44KL44CC5LuW44Gv77yQ44CCCmRlZiB3cml0ZUJvYXJkKGxzKXsKICBpbml0Qm9hcmQoKSwKICB3cml0ZUJvYXJkMShscykKfTsKCmRlZiB3cml0ZUJvYXJkMShscykKICBpZihudWxsPyhscykpCiAgICAjdAogIGVsc2UKICAgIGxldChpLGNhYXIobHMpKShqLGNhZGFyKGxzKSl7CiAgICAgbWF0W2ksal0gOj0gMSwKICAgICB3cml0ZUJvYXJkMShjZHIobHMpKQogICAgfTsKCiXooYzliJfjga7liJ3mnJ/ljJYKZGVmIGluaXRCb2FyZCgpCiAgbGV0KGksMCkoaiwwKQogICAgZm9yKGk6PTEsaTw9c2l6ZSxpKyspCiAgICAgIGZvcihqOj0xLGo8PXNpemUsaisrKQogICAgICAgIG1hdFtpLGpdIDo9IDA7Cgol44Gd44Gu6YWN572u44Gv44K744O844OV44GL77yf44K744O844OV44Gq44KJ6KGo56S644GZ44KL44CCCmRlZiBzYWZlPyhscyl7CiAgbGVuZ3RoTHMgOj0gW10sCiAgd3JpdGVCb2FyZChscyksCiAgY2F0Y2ggdGFnCiAgbGV0KGksMCkoaiwwKXsKICAgIGZvcihpOj0xLGk8PXNpemUsaSsrKQogICAgICBmb3Ioajo9MSxqPD1zaXplLGorKykKICAgICAgICB3aGVuKG1hdFtpLGpdPTEgJiYgbm90KHNhZmUxPyhpLGopKSkKICAgICAgICAgICAgdGhyb3cgdGFnICNmLAogICAgcHJpbnQobHMpfX07CgogICAgICAgICAgCmRlZiBzYWZlMT8oeCx5KQogIGNhdGNoIHRhZ3sKICBsZXQoaSwwKShqLDApCiAgICBmb3IoaTo9eCxpPD1zaXplLGkrKykKICAgICAgZm9yKGo6PXksajw9c2l6ZSxqKyspCiAgICAgICAgd2hlbihtYXRbaSxqXT0xICYmIGkhPXggJiYgaiE9eSAmJiBjaGVjayh4LHksaSxqKSkKICAgICAgICAgIHRocm93IHRhZyAjZiwKICAjdH07Cgol6Led6Zui44KS6KiI566X44GX44GZ44Gn44Gr44GC44Gj44Gf6Led6Zui44GL44Gp44GG44GL44KS5Yik5a6a44GZ44KL44CCCmRlZiBjaGVjayh4LHksaSxqKQogIGxldChkLG5vcm0oeCx5LGksaikpCiAgICBpZihtZW1iZXIoZCxsZW5ndGhMcykpCiAgICAgICN0CiAgICBlbHNlewogICAgICBsZW5ndGhMcyA6PSBjb25zKGQsbGVuZ3RoTHMpLAogICAgICAjZn07Cgol44Om44O844Kv44Oq44OD44OJ6Led6Zui44KS6KiI566XCmRlZiBub3JtKHgseSxpLGopCiAgIHNxcnQoYWJzKHgtaSleMithYnMoeS1qKV4yKTsKICAgICAg
Main.java:1: error: illegal character: '#'
#!sapphire
^
Main.java:1: error: class, interface, or enum expected
#!sapphire
^
Main.java:5: error: class, interface, or enum expected
def mat makeMat(size,size);
^
Main.java:7: error: class, interface, or enum expected
%????????
^
Main.java:7: error: illegal character: '\u3002'
%????????
^
Main.java:11: error: class, interface, or enum expected
%n*n????????????????
^
Main.java:11: error: illegal character: '\u3002'
%n*n????????????????
^
Main.java:19: error: class, interface, or enum expected
%??????????????????f????
^
Main.java:19: error: illegal character: '\u3002'
%??????????????????f????
^
Main.java:30: error: illegal character: '#'
#f
^
Main.java:35: error: class, interface, or enum expected
%?????????
^
Main.java:38: error: class, interface, or enum expected
%?????????????????????????
^
Main.java:38: error: illegal character: '\u3002'
%?????????????????????????
^
Main.java:38: error: illegal character: '\u3002'
%?????????????????????????
^
Main.java:44: error: class, interface, or enum expected
def writeBoard1(ls)
^
Main.java:46: error: illegal character: '#'
#t
^
Main.java:53: error: class, interface, or enum expected
%??????
^
Main.java:60: error: class, interface, or enum expected
%????????????????????
^
Main.java:60: error: illegal character: '\uff1f'
%????????????????????
^
Main.java:60: error: illegal character: '\u3002'
%????????????????????
^
Main.java:69: error: illegal character: '#'
throw tag #f,
^
Main.java:73: error: class, interface, or enum expected
def safe1?(x,y)
^
Main.java:79: error: illegal character: '#'
throw tag #f,
^
Main.java:80: error: illegal character: '#'
#t};
^
Main.java:82: error: class, interface, or enum expected
%????????????????????????
^
Main.java:82: error: illegal character: '\u3002'
%????????????????????????
^
Main.java:86: error: illegal character: '#'
#t
^
Main.java:89: error: illegal character: '#'
#f};
^
Main.java:91: error: class, interface, or enum expected
%???????????
^
29 errors