Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 2.24 KB | None | 0 0
  1. let INFINI = 66666666;;
  2. let mQuad = ref (INFINI, INFINI, INFINI, INFINI);;
  3. let pBorne = ref 0;;
  4.  
  5. let addt x y = x + y;;
  6. let mult x y = x * y;;
  7. let sous x y = x - y;;
  8. let div  x y = if y = 0 then 0 else x / y;;
  9.  
  10. let operateurs = make_vect 4 addt;;
  11. operateurs.(0) <- addt;;
  12. operateurs.(1) <- mult;;
  13. operateurs.(2) <- sous;;
  14. operateurs.(3) <- div;;
  15.  
  16. let borne a b c d =
  17.  
  18.     let plage = make_vect 3025 0 in
  19.    
  20.    
  21.     (*****)
  22.    
  23.     let permutations l =
  24.    
  25.         let rec permut fixe = fun
  26.             | [] [] -> [fixe]
  27.             | debut [] -> []
  28.             | debut (x::suite) -> (permut (fixe @ [x]) [] (debut @ suite)) @ (permut fixe (debut @ [x]) suite)
  29.         in
  30.    
  31.         permut [] []
  32.     in
  33.    
  34.     let perm = vect_of_list (permutations [a;b;c;d]) in
  35.    
  36.     for cur_perm = 0 to (vect_length perm - 1) do
  37.         for op1 = 0 to 3 do
  38.             for op2 = 0 to 3 do
  39.                 for op3 = 0 to 3 do
  40.                     let p3 = operateurs.(op3) in
  41.                     let p2 = operateurs.(op2) in
  42.                     let p1 = operateurs.(op1) in
  43.                    
  44.                     let a = hd (perm.(cur_perm)) in
  45.                     let b = hd ( tl (perm.(cur_perm)) ) in
  46.                     let c = hd ( tl (tl (perm.(cur_perm))) ) in
  47.                     let d = hd ( tl (tl (tl (perm.(cur_perm)))) ) in
  48.                    
  49.                     if (p3 (p2 (p1 a b) (c)) (d)) >= 0 then
  50.                         plage.( p3 (p2 (p1 a b) (c)) (d) ) <- succ (plage.( p3 (p2 (p1 a b) (c)) (d) ));
  51.                
  52.                     if (p2 (p1 (a) (b)) (p3 (c) (d))) >= 0 then
  53.                         plage.( p2 (p1 (a) (b)) (p3 (c) (d)) ) <- succ (plage.( p2 (p1 (a) (b)) (p3 (c) (d)) ));
  54.    
  55.                     if (p1 (a) (p2 (b) (p3 c d))) >= 0 then
  56.                         plage.( p1 (a) (p2 (b) (p3 c d)) ) <- succ (plage.( p1 (a) (p2 (b) (p3 c d)) ));
  57.    
  58.                     if (p3 (p1 (a) (p2 b c)) (d)) >= 0 then
  59.                         plage.( p3 (p1 (a) (p2 b c)) (d) ) <- succ (plage.( p3 (p1 (a) (p2 b c)) (d) ));
  60.    
  61.                     if (p1 (a) (p3 (p2 b c) (d))) >= 0 then
  62.                         plage.( p1 (a) (p3 (p2 b c) (d)) ) <- succ (plage.( p1 (a) (p3 (p2 b c) (d)) ));
  63.                 done
  64.             done
  65.         done
  66.     done;
  67.    
  68.     (*****)
  69.    
  70.    
  71.    
  72.    
  73.     let indice = ref 1 in
  74.     while plage.(!indice) > 0 do
  75.         incr indice
  76.     done;
  77.    
  78.     (!indice - 1)
  79. ;;
  80.  
  81. for a = 1 to 9 do
  82.     for b = a+1 to 9 do
  83.         for c = b+1 to 9 do
  84.             for d = c+1 to 9 do
  85.                 let boborne = borne a b c d in
  86.                 if (!pBorne) < boborne
  87.                 then
  88.                     begin
  89.                     pBorne := boborne;
  90.                     mQuad := (a,b,c,d)
  91.                     end
  92.             done
  93.         done
  94.     done
  95. done;;
  96.  
  97. mQuad;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement