Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let INFINI = 66666666;;
- let mQuad = ref (INFINI, INFINI, INFINI, INFINI);;
- let pBorne = ref 0;;
- let addt x y = x + y;;
- let mult x y = x * y;;
- let sous x y = x - y;;
- let div x y = if y = 0 then 0 else x / y;;
- let operateurs = make_vect 4 addt;;
- operateurs.(0) <- addt;;
- operateurs.(1) <- mult;;
- operateurs.(2) <- sous;;
- operateurs.(3) <- div;;
- let borne a b c d =
- let plage = make_vect 3025 0 in
- (*****)
- let permutations l =
- let rec permut fixe = fun
- | [] [] -> [fixe]
- | debut [] -> []
- | debut (x::suite) -> (permut (fixe @ [x]) [] (debut @ suite)) @ (permut fixe (debut @ [x]) suite)
- in
- permut [] [] l
- in
- let perm = vect_of_list (permutations [a;b;c;d]) in
- for cur_perm = 0 to (vect_length perm - 1) do
- for op1 = 0 to 3 do
- for op2 = 0 to 3 do
- for op3 = 0 to 3 do
- let p3 = operateurs.(op3) in
- let p2 = operateurs.(op2) in
- let p1 = operateurs.(op1) in
- let a = hd (perm.(cur_perm)) in
- let b = hd ( tl (perm.(cur_perm)) ) in
- let c = hd ( tl (tl (perm.(cur_perm))) ) in
- let d = hd ( tl (tl (tl (perm.(cur_perm)))) ) in
- if (p3 (p2 (p1 a b) (c)) (d)) >= 0 then
- plage.( p3 (p2 (p1 a b) (c)) (d) ) <- succ (plage.( p3 (p2 (p1 a b) (c)) (d) ));
- if (p2 (p1 (a) (b)) (p3 (c) (d))) >= 0 then
- plage.( p2 (p1 (a) (b)) (p3 (c) (d)) ) <- succ (plage.( p2 (p1 (a) (b)) (p3 (c) (d)) ));
- if (p1 (a) (p2 (b) (p3 c d))) >= 0 then
- plage.( p1 (a) (p2 (b) (p3 c d)) ) <- succ (plage.( p1 (a) (p2 (b) (p3 c d)) ));
- if (p3 (p1 (a) (p2 b c)) (d)) >= 0 then
- plage.( p3 (p1 (a) (p2 b c)) (d) ) <- succ (plage.( p3 (p1 (a) (p2 b c)) (d) ));
- if (p1 (a) (p3 (p2 b c) (d))) >= 0 then
- plage.( p1 (a) (p3 (p2 b c) (d)) ) <- succ (plage.( p1 (a) (p3 (p2 b c) (d)) ));
- done
- done
- done
- done;
- (*****)
- let indice = ref 1 in
- while plage.(!indice) > 0 do
- incr indice
- done;
- (!indice - 1)
- ;;
- for a = 1 to 9 do
- for b = a+1 to 9 do
- for c = b+1 to 9 do
- for d = c+1 to 9 do
- let boborne = borne a b c d in
- if (!pBorne) < boborne
- then
- begin
- pBorne := boborne;
- mQuad := (a,b,c,d)
- end
- done
- done
- done
- done;;
- mQuad;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement