Ocaml 有没有另一种短一点的方法来写下这段代码?(攻击和被攻击函数)

Ocaml 有没有另一种短一点的方法来写下这段代码?(攻击和被攻击函数),ocaml,n-queens,Ocaml,N Queens,有没有其他方法可以用更短的方式写下这段代码? OCAML,不是客观的CAML let board = [|('a', 1); ('b', 2); ('c', 3); ('d', 4);('e', 5); ('f', 6); ('g', 7); ('h', 8)|];; let int_of_col letter = int_of_char letter-96;; let abs x = if x < 0 then - x else x;; let att

有没有其他方法可以用更短的方式写下这段代码? OCAML,不是客观的CAML

let board = [|('a', 1); ('b', 2); ('c', 3); ('d', 4);('e', 5); ('f', 6); 
              ('g', 7); ('h', 8)|];;

let int_of_col letter = int_of_char letter-96;;

let abs x = if x < 0 then - x else x;;

let attack (a,x)(b,y) = ((int_of_col a - int_of_col b)*(x-y)) 
           = 0 || (abs(int_of_col a - int_of_col b) = abs(x-y));;

let attacked listing = 
    let out = Array.make 8 false in
    for i=0 to 7 do
        for j=0 to 7 do
            if(i != j) then
                if(attack listing.(i) listing.(j)) then out.(i) <- true
                done
            done;
        out;;
let board=[|('a',1);('b',2);('c',3);('d',4);('e',5);('f',6);
(g',7);(h',8);;
让int_of_col letter=int_of_char letter-96;;
设abs x=如果x<0则-x否则x;;
让攻击(a,x)(b,y)=((a列的整数-b列的整数)*(x-y))
=0 | |(abs(a列的int_-b列的int_)=abs(x-y));;
让列表=
释放=数组。将8设为假
对于i=0到7 do
对于j=0到7 do
如果(i!=j)那么

如果(攻击列表。(i)列表。(j)),那么out.(i)abs在ocaml中存在,无需重新实现<代码>被攻击
可以简化如下:

let attacked listing =                                                          
  Array.map (fun i -> Array.exists (fun j -> i != j && attack i j) listing) listing

非常感谢戴文!我很感激!