Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let board = [|
- ('a', 1); ('b', 2); ('c', 3); ('d', 4);
- ('e', 5); ('f', 6); ('g', 7); ('h', 8)
- |];;
- (*** 1 ***)
- let int_of_col = fun x ->
- match x with
- | 'a' -> 1
- | 'b' -> 2
- | 'c' -> 3
- | 'd' -> 4
- | 'e' -> 5
- | 'f' -> 6
- | 'g' -> 7
- | 'h' -> 8;;
- (*** 2 ***)
- let attack = fun (k,b) (l,d) ->
- if int_of_col k == int_of_col l && b == d then
- false
- else if abs(int_of_col k - int_of_col l) * abs(b - d) == 0
- || abs(int_of_col k - int_of_col l) == abs(b - d)
- then
- true
- else
- false;;
- (*** 3 ***)
- let attacked = fun array ->
- let war = [|false; false; false; false; false; false; false; false|] in
- for i = 0 to (Array.length array)-1 do
- for j = 0 to (Array.length array)-1 do
- if attack (array.(i)) (array.(j)) then
- (war.(i) <- true;
- war.(j) <- true;);
- done
- done;
- war;;
- (*** 4 ***)
- let checkIfTrue = fun state ->
- if state then
- false
- else
- true;;
- let safe = fun s ->
- Array.for_all checkIfTrue (attacked s);;
- safe [|('a', 7); ('b', 2); ('d', 3);
- ('e', 6); ('f', 8); ('g', 5); ('h', 1)|];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement