Guest User

Untitled

a guest
Jul 30th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 23.85 KB | None | 0 0
  1. (*********************************BLOC DE FONCTION EN VRAC (REUTILISABLES)*************************************)
  2. let string_of_char = fun a ->
  3.     String.make 1 a;;
  4.  
  5. let rec aux2 l elem res2 = match l with
  6.     []->res2
  7.     |h::t-> aux2 t elem ((elem^h)::res2) ;;
  8.    
  9. let produitCartesien l1 l2 =
  10.     let rec aux l1 l2 res = match l1 with
  11.         []->res
  12.         |h::t-> aux t l2 res@(aux2 l2 h [])
  13.     in aux l1 l2 [] ;;
  14.  
  15. (*let concatFiltrage l1 l2 = (* TODO concat 2 liste en évitant doubles nécessite let equaltMot m1 m2*)
  16.     let rec aux ltmp res = match ltmp with
  17.         []->res
  18.         |h::t-> begin
  19.                     match l2 with
  20.                         []-> aux t (h::res)
  21.                         |h2::t2-> if (h=h2) then aux t res
  22.                 end
  23.     in aux l1 l1 ;;*)
  24.  
  25. (**********************************BLOC DE LECTURE ET D ANALYSE DES VARIABLES**********************************)
  26. let rec appartient l arg = match l with
  27.     []->false
  28.     |h::t-> if h=arg then true
  29.             else appartient t arg
  30.     ;;
  31.    
  32. let lecture s =
  33.     let rec aux s2 var = match s2 with    (*compte le nombre de variable*)
  34.         ""-> var
  35.         |a-> if ((String.get a 0)!='+' && (String.get a 0)!='.' && (String.get a 0)!='!') then(*pas un opérateur*)
  36.                     if (appartient var (String.get a 0)) then aux (String.sub a 1 ((String.length a)-1)) var (*h € var go *)
  37.                     else aux (String.sub a 1 ((String.length a)-1)) (var@[(String.get a 0)]) (*on rajoute h à var *)
  38.                 else aux (String.sub a 1 ((String.length a)-1)) var
  39.         in aux s [] ;;
  40.  
  41. let lectureString s = List.map (string_of_char) (lecture s) ;;        
  42.  
  43. (**********************************BLOC DE GESTION DE COMPLETION D UN MOT**********************************)
  44.  
  45. (************SOUS BLOC DE DETECTION DES VARIABLES MANQUANTES
  46.              ET CREATION DES LISTES CORRESPONDANTES***********)
  47. let soustraction mot var =
  48.     let rec aux mot var res = match var with
  49.         []->res
  50.         |h::t-> if (String.contains mot h) then aux mot t res (*rentre toujours ici*)
  51.                 else aux mot t (h::res)
  52.     in aux mot var [] ;;
  53.  
  54. let preparation manquants = (*prends liste de char manquants et renvoit liste de liste(binome) contenant une var et son opposé
  55.                              ex ['a';'b']->[ ["a";"!a"] ; ["b";"!b"] ]*)
  56.     let rec aux l res = match l with
  57.         []->res
  58.         |h::t-> aux t (((String.make 1 h)::("!"^(String.make 1 h))::[])::res)
  59.     in aux manquants [] ;;
  60.  
  61.  
  62. (************SOUS BLOC DE CREATION DES PERMUTATIONS***********)
  63.  
  64. let rec permutationBinaire l =
  65.     let rec aux l2 res = match l2 with
  66.         []->[]
  67.         |h::t-> if (t!=[]) then aux t ((produitCartesien res (List.hd t)))
  68.                 else res
  69.     in aux l (List.hd l) ;;
  70. (* permutationBinaire [ ["a";"!a"] ; ["b";"!b"] ; ["c";"!c"] ]
  71. <=>(produitCartesien ["c";"!c"] (produitCartesien ["a";"!a"] ["b";"!b"])) ;;
  72. => renvoit une string list de toutes les permutations binaires *)
  73.  
  74. (********SOUS BLOC D ASSEMBLAGE DU MOT ET DES PERMS****)
  75.  
  76. let add s l = (*concat d'une string sur tout les elements d'une list -> renvoit une liste de mot a ajouté à la phrase *)
  77.     let rec aux l2 res = match l2 with
  78.         []->res
  79.         |h::t-> aux t ((h^s)::res)
  80.     in aux l [] ;;
  81.    
  82. (*********ASSEMBLAGE DE TOUT LES SOUS BLOCS************)
  83.  
  84. let completion mot var = (* prends en entrée le tableau de chars des variables, et une string correspondant au mot à compléter *)
  85.     add mot (permutationBinaire (preparation (soustraction mot var) ) ) ;;
  86. (* utilisation: completion "a" ['a';'b';'c';'d'] ;; *)
  87.  
  88.  
  89.  
  90.        
  91. (**********************************BLOC DE COMPLETION DE LA PHRASE**************************************)
  92.  
  93. let rec appartenance s l = match l with (*vérifie que toutes les caractères de l ou leurs négations sont dans s *)
  94.     []->true
  95.     |h::t-> if (String.contains s h=false) then false
  96.          else appartenance s t
  97.  
  98. (*let conversionDijonctive sDepart =
  99.     let rec aux var s mot res = match s with
  100.         ""->res
  101.         |a->begin
  102.             match (String.get a 0 ) with
  103.                 '+'-> begin
  104.                         match (appartenance mot var) with
  105.                             true->(* Si mot Contient toutes les vars/leurs négations *)
  106.                                 aux var ( String.sub s 1 ((String.length s)-1) ) (* <=>reste de s *)  ""(* on démarre un nouveau mot=>nouvelle String *) (mot::res)(* on ajoute le mot à res *)
  107.                             |false-> aux var ( String.sub s 1 ((String.length s)-1) )(* <=>reste de s *)  ""(* on démarre un nouveau mot=>nouvelle String *) (concatFiltrage (completion mot var) res)(* pas de (completion mot var)@res car il faut filtrer les doubles aussi *)(*complétion du mot*)
  108.                       end
  109.                 |'!'-> aux var ( String.sub s 2 ((String.length s)-2) )(* <=>reste de s *) (mot^(String.sub a 0 1)^(String.sub a 1 1))(* on continue de construire le mot en prenant deux lettres car on tombe sur une négation *) res
  110.                 |_-> aux var ( String.sub s 1 ((String.length s)-1) )(* <=>reste de s *) (mot^(String.sub a 0 1))(* on continue de construire le mot *) res
  111.             end
  112.     in aux (lecture sDepart) (sDepart^"+") "" [] ;; (* sDepart^"+" pour gérer le cas abcd+a sinon a ne sera pas compléter*)
  113. *) 
  114.  
  115.    
  116.    
  117.    
  118.    
  119.         let string_of_char = fun a ->
  120.     String.make 1 a;;
  121.  
  122.     let exclusive_or = fun a b ->
  123.     if a=b
  124.             then "0"
  125.             else "1"
  126.     ;;
  127.  
  128.     (*conversion de décimal en binaire*)
  129.     let rec bin_of_dec_root = fun nb_dec ->
  130.             if nb_dec = 0 then
  131.                     ""
  132.                     else
  133.                     (bin_of_dec_root (nb_dec/2))^(string_of_int (nb_dec mod 2));;
  134.      
  135.     let rec add_zeros = fun string nb_of_zeros ->
  136.             if nb_of_zeros = 0 then string
  137.             else
  138.             add_zeros ("0"^string) (nb_of_zeros-1)
  139.             ;;
  140.     let bin_of_dec = fun nb_bt nb_dec ->
  141.             let result = bin_of_dec_root nb_dec in
  142.             add_zeros result (nb_bt-(String.length result))
  143.             ;;
  144.      
  145.            
  146.     let gray_of_bin = fun bin_string ->
  147.     let rec aux = fun index gray_string ->
  148.                     if index>=(String.length bin_string) then gray_string
  149.                     else
  150.                     aux (index+1) (gray_string^(exclusive_or (String.get bin_string (index-1)) (String.get bin_string index)))
  151.     in aux 1 (string_of_char(String.get bin_string 0))
  152.     ;;    
  153.            
  154.     let gray_of_dec = fun nb_dec nb_bit->
  155.             gray_of_bin (bin_of_dec nb_bit nb_dec)
  156.             ;;
  157.      
  158.     (*placer ici fst de split list_arg ou snd de split list_arg*)
  159.     let rec get_gray = fun word list_arg ->
  160.             match list_arg with
  161.             [] -> ""
  162.             |h::t -> let  index = (String.index word (String.get h 0)) in
  163.                                     if index>0 then
  164.                                             if (String.get word (index-1))='!'
  165.                                                     then "0"^(get_gray word t)
  166.                                                     else "1"^(get_gray word t)
  167.                                             else "1"^(get_gray word t)
  168.     ;;
  169.      
  170.     let bin_of_gray = fun gray_string ->
  171.     let rec aux = fun index bin_string ->
  172.                     if index>=(String.length gray_string) then bin_string
  173.                     else
  174.                     aux (index+1) (bin_string^(exclusive_or (String.get bin_string (index-1)) (String.get gray_string index)))
  175.     in aux 1 (string_of_char(String.get gray_string 0))
  176.     ;;
  177.      
  178.     let rec int_of_bin = fun bin_string ->
  179.             if (String.length bin_string)>=1
  180.                     then
  181.                     if ((String.get bin_string 0)='1')
  182.                             then
  183.                             (int_of_float (2.**(float_of_int ((String.length bin_string)-1))))+int_of_bin ( String.sub bin_string 1 ((String.length bin_string)-1))
  184.                             else
  185.                             int_of_bin ( String.sub bin_string 1 ((String.length bin_string)-1))
  186.             else 0
  187.     ;;
  188.      
  189.     let get_index = fun word list_arg ->
  190.             int_of_bin( bin_of_gray ( get_gray word list_arg));;
  191.      
  192.            
  193.     (*récupération en utilisant des coordonnées*)
  194.     let get_expr = fun nb_gray list_arg ->
  195.             let rec aux = fun ret nb list_arg ->
  196.                     if nb="" then
  197.                             ret
  198.                             else
  199.                                     let variable =  (if (String.get nb 0)='1' then "" else "!") in
  200.                                     aux (ret^variable^(List.hd list_arg)) (String.sub nb 1 ((String.length nb)-1)) (List.tl list_arg)
  201.             in aux "" nb_gray list_arg;;
  202.     (*attention liste d'arguments splittée*)
  203.     (*récupère un mot en utilisant des coordonnées*)
  204.     let get_word = fun coord list_arg ->
  205.     (get_expr (gray_of_dec(fst coord) (List.length (fst list_arg))) (fst list_arg))^(get_expr (gray_of_dec(snd coord) (List.length (snd list_arg))) (snd list_arg))
  206.     ;;    
  207.     (*affect en utilisant du code gray*)
  208.      
  209.     let affect2 = fun word list_arg table ->
  210.             let rec aux = fun index table ->
  211.                     if index = 0 then
  212.                             match table with
  213.                             [h] -> [1]
  214.                             |h::t -> 1::t
  215.                     else
  216.                             (List.hd table) :: (aux (index-1) (List.tl table))
  217.             in aux (get_index word (snd list_arg)) table
  218.     ;;
  219.     let affect = fun word list_arg table ->
  220.             let rec aux = fun index table ->
  221.                     if index = 0 then
  222.                             (affect2 word list_arg (List.hd table))::(List.tl table)
  223.                             else
  224.                            
  225.                             (List.hd table) :: (aux (index -1) (List.tl table))
  226.                     in aux (get_index word (fst list_arg)) table;;
  227.                    
  228.     let rec create_table = fun list_word list_arg table ->
  229.             match list_word with
  230.                     []->table
  231.                     |h::t-> create_table t  list_arg (affect h list_arg table)
  232.     ;;
  233.      
  234.     (*nombre de colonnes et de lignes en fonction du nombre d'arguments*)
  235.     let rec create_column = fun nb_lignes content ->
  236.             if nb_lignes = 0
  237.                     then
  238.                     []
  239.                     else
  240.                     [content]@create_column (nb_lignes-1) content
  241.     ;;
  242.      
  243.     let init_tab = fun list_arg content ->
  244.             let rec aux = fun nb_colonnes nb_lignes content ->
  245.                     if nb_colonnes = 0
  246.                             then    
  247.                             []
  248.                             else
  249.                             (create_column nb_lignes content) :: aux (nb_colonnes-1) nb_lignes content
  250.             in
  251.             let     nb_colonnes = int_of_float (2.**(float_of_int((List.length list_arg)/2))) in
  252.             let nb_lignes =         if ((List.length list_arg) mod 2) = 0
  253.                                                     then
  254.                                                     int_of_float (2.**(float_of_int((List.length list_arg)/2)))
  255.                                                     else
  256.                                                     int_of_float (2.**(float_of_int(((List.length list_arg)/2)-1)))
  257.             in
  258.                     aux nb_colonnes nb_lignes content
  259.             ;;
  260.      
  261.      
  262.      
  263.     let decompose = fun s ->
  264.             let rec aux = fun s return ->
  265.                     if (String.contains s '+') then
  266.                     let borne = (String.index s '+') in aux (String.sub s (borne+1) ((String.length s)-(borne+1))) (return@[(String.sub s 0 borne)])
  267.                     else
  268.                     return@[s]
  269.             in aux s []
  270.     ;;
  271.      
  272.     let split = fun li ->
  273.     let length = List.length li in let enum = (length/2)+((mod) length 2) in
  274.     let rec aux = fun li li2 it ->
  275.             if it = 0 then (li, li2) else aux (li@[(List.hd li2)]) (List.tl li2) (it-1)
  276.     in aux [] li enum;;
  277.      
  278.     let rec print_line = fun list->
  279.     match list with
  280.     []->"\n"
  281.     |h::t-> h^" "^(print_line t);;
  282.      
  283.     let print_table = fun table ->
  284.     let rec aux = fun table s ->
  285.     match table with
  286.     []->print_string s
  287.     |h::t -> aux t (s^(print_line h))
  288.     in aux table "";;
  289.      
  290.     let get_value = fun coord table ->
  291.             List.nth (List.nth table (fst coord)) (snd coord);;
  292.      
  293.     (*sondageV*)
  294.     let sonde_verticale = fun coord table ->
  295.             let rec aux = fun coord looped ret ->
  296.                     if (snd coord) >= (List.length (List.hd table)) then
  297.                             if (looped) then ret
  298.                                     else aux ((fst coord), 0) true ret
  299.                             else
  300.                                     if (get_value coord table)=1 then aux ((fst coord),((snd coord)+1)) looped (ret+1)
  301.                                             else ret
  302.             in let line = aux coord false 0 in
  303.                     if line<(List.length (List.hd table)) then line
  304.                             else (List.length (List.hd table));;
  305.     (*sondageH*)
  306.     let sonde_horizontal = fun coord table ->
  307.             let rec aux = fun coord looped ret ->
  308.                     if (fst coord) >= (List.length table) then
  309.                             if (looped) then ret
  310.                                     else aux (0, (snd coord)) true ret
  311.                             else
  312.                                     if (get_value coord table)=1 then aux (((fst coord)+1),(snd coord)) looped (ret+1)
  313.                                             else ret
  314.             in let line = aux coord false 0 in
  315.                     if line<(List.length table) then line
  316.                             else (List.length table);;
  317.      
  318.      
  319.      
  320.     (*partie explore*)
  321.      let pow = fun nb ->
  322.             let rec aux = fun i tmp ->
  323.         if (  (2.0 ** ( float_of_int((tmp+1)) )) > (float_of_int i)  )
  324.             then tmp
  325.         else aux i (tmp+1)
  326.             in aux nb 0;;
  327.     let pow2 = fun nb -> int_of_float (2.0**(float_of_int (pow nb))) ;;
  328.      
  329.     let min_list = fun list ->
  330.             let rec aux = fun min list ->
  331.                     match list with
  332.                             [] -> min
  333.                             |h::t -> let min_loc = (if (min < h) then min else h) in aux min_loc t
  334.             in aux (List.hd list) list;;
  335.      
  336.     let get_liste = fun coord it taille_table->
  337.             let rec aux = fun coord it ret ->
  338.                     if it = 0
  339.                             then ret
  340.                             else let new_coord = ((fst coord), (if ((snd coord)+1)=taille_table then 0 else (snd coord)+1)) in
  341.                                     aux new_coord (it-1) (ret@[new_coord])
  342.             in aux coord (it-1) [coord];;
  343.      
  344.     let vary_col = fun coord nb_col taille->
  345.             let rec aux = fun list nb_col->
  346.                     if (nb_col = 0)
  347.                             then
  348.                                     list
  349.                             else let x = if ((fst (List.hd list))+1)<taille then (fst (List.hd list))+1 else 0 in
  350.                              aux (( x, snd (List.hd list))::list) (nb_col-1)
  351.             in aux [coord] nb_col;;
  352.            
  353.     let vary_line = fun coord nb_ligne taille->
  354.             let rec aux = fun list nb_ligne->
  355.                     if (nb_ligne = 0)
  356.                             then
  357.                                     list
  358.                             else let y = (if ((snd (List.hd list))+1)<taille then (snd (List.hd list))+1 else 0) in
  359.                             aux (((fst (List.hd list)), y)::list) (nb_ligne-1)
  360.             in aux [coord] nb_ligne;;
  361.            
  362.     let explore = fun coord table list_arg-> (*groupe*)
  363.             let line = sonde_verticale coord table in
  364.                     if line > 0 then
  365.                             let liste = get_liste coord (pow2 line) (List.length (List.hd table)) in
  366.                                     let min_h = min_list (List.map pow2 (List.map (fun x->sonde_horizontal x table) liste)) in
  367.                                             let min_v = pow2 line in
  368.                                                     let list_coord = List.map (fun x -> vary_col x (min_h-1) (List.length table)) (vary_line coord (min_v-1)(List.length (List.hd table))) in
  369.                                                             List.map (fun x-> get_word x list_arg) (List.flatten list_coord)
  370.                                    
  371.                     else [];;
  372.      
  373.      
  374.      
  375.      
  376.      let rec truc i tmp =
  377.     if (  (2.0 ** ( float_of_int((tmp+1)) )) > (float_of_int i)  )
  378.         then tmp
  379.     else truc i (tmp+1) ;;
  380. (*    
  381. let min_list = fun list ->
  382.     let rec aux = fun min list ->
  383.         match list with
  384.             [] -> min
  385.             |h::t -> let min_loc = (if min<h) then min else h) in aux min_loc t
  386.     in aux (List.hd list) list;;
  387. *)
  388.  
  389. let min_list = fun list ->
  390.     let rec aux = fun min list ->
  391.             match list with
  392.                     [] -> min
  393.                     |h::t -> let min_loc = (if (min < h) then min else h) in aux min_loc t
  394.     in aux (List.hd list) list;;
  395.    
  396. let head = fun nb list ->
  397.     let rec aux = fun nb list ret ->
  398.         if nb = 0
  399.             then ret
  400.             else aux (nb -1) (List.tl list) (ret@[(List.hd list)])
  401.     in aux nb list []
  402.  
  403.    
  404.    
  405.    
  406.    
  407.    
  408. (*
  409. let rec filtrageAux3 mot lres b = match lres with(* renvoie vrai si mot trouvé *)
  410.     []->b
  411.     |h::t-> if (h=mot)
  412.                 then true
  413.                 else filtrageAux3 mot t b ;;
  414.    
  415. let rec filtrageAux2 lres lretour b = match lretour with (* prends une liste de string provenant de lres et la liste de string lretour provenant de explore *) (*renvoi vrai si tout les mots de lretour trouvé dans lres *)
  416.     []->b
  417.     |h::t-> if ( filtrageAux3 h lres false )
  418.                 then filtrageAux2 lres t b
  419.                 else false ;;
  420.    
  421. let rec filtrageAux tres lretour b = match tres with (* prends en parametre gRes (une list de list de string) et le retour de explorer (une liste de string) retourne un boolen false si chacun des membres du retour se trouvent dans un meme membre de gRes *) (*renvoit true si lretour n'est pas trouvé <=> renvoit true si on peut ajouter*)
  422.     []-> b
  423.     |h::t-> if ( filtrageAux2 h lretour true)
  424.                 then filtrageAux t lretour false
  425.                 else filtrageAux t lretour b ;;
  426.            
  427. let filtrage = fun lres lretour -> filtrageAux lres lretour true ;;    
  428.  
  429.  
  430. let rec postTraitementAux tab tabtmp res = match tabtmp with
  431.     |[]->res
  432.     |h::t-> if ( filtrage (tabtmp@t) h ) (* tabtmp <=> tab - le membre en train d'etre scanné pour éviter qu'il ne se retrouve lui meme lors du filtrage *)
  433.                 then postTraitementAux tab (tabtmp::h) (h::res)
  434.                 else postTraitementAux tab (tabtmp::h) res ;;
  435.  
  436. let postTraitement t = postTraitementAux (parcours t 0 0) (parcours t 0 0) [] ;;
  437. *)
  438. let rec is_in = fun element list ->
  439.    match list with
  440.    []->false
  441.    |h::t -> if h=element then true else is_in element t;;
  442.    
  443. let rec equals2 = fun list1 list2->
  444.    match list1 with
  445.    []-> true
  446.    |h::t -> (is_in h list2)&&(equals2 t list2);;  
  447.  
  448. let rec contained = fun list element ->
  449.    match list with
  450.       []->false
  451.       |h::t-> if (equals2 h element) then true else contained t element;;
  452.      
  453. let clear_list = fun list ->
  454.    let rec aux = fun ret_list buffer->
  455.       match buffer with
  456.          [] -> ret_list
  457.          |h::t-> aux (if contained ret_list h then ret_list else (h::ret_list)) t
  458.    in aux [] list;;
  459.  
  460.  
  461.  
  462.  
  463.    
  464.  
  465.  
  466. let rec removeVoid = fun list ->
  467.     match list with
  468.         []->[]
  469.         |h::t->if h=[]
  470.                 then removeVoid t
  471.                 else (h::(removeVoid t)) ;;
  472.  
  473. let rec pick element list =
  474.     match list with
  475.         []->[]
  476.         |h::t->if h=element
  477.                    then t
  478.                    else h::(pick element t);;
  479.                  
  480. let rec contains = fun elem list ->
  481.     match list with
  482.         []->false
  483.         |h::t->if (h=elem)
  484.                     then true
  485.                     else contains elem t ;;
  486.                    
  487. let rec inclusAux = fun list1 list2 ->
  488.     match list1 with
  489.         []->true
  490.         |h::t->(contains h list2) && (inclusAux t list2) ;;        
  491.                    
  492. let rec inclus = fun list1 list2 ->
  493.     match list2 with
  494.         []->false
  495.         |h::t->(inclusAux list1 h) || (inclus list1 t) ;;
  496.                
  497. let filtrage tab =
  498.     let rec aux tabtmp res =
  499.         match tabtmp with
  500.             []->res
  501.             |h::t->if (inclus h (pick h tab))
  502.                       then aux t res
  503.                       else aux t (h::res)
  504.     in aux tab [] ;;
  505.      
  506.      
  507.      
  508.      
  509.      
  510.  
  511.      
  512.  
  513. let firstLetter mot =(* fonction qui renvoit la 1 ere lettre d'un mot *)
  514.     if (String.get mot 0)='!'
  515.         then "!"^(String.make 1 (String.get mot 1))
  516.         else (String.make 1 (String.get mot 0))
  517.     ;;
  518.  
  519. let containsLetter = fun lettre string ->
  520.    if (String.length lettre) = 1 then
  521.       if (String.contains string (String.get lettre 0))
  522.         then if (String.index string (String.get lettre 0))>0
  523.             then
  524.                 not( (String.get string (((String.index string (String.get lettre 0)))-1)) = '!')
  525.             else true
  526.         else false
  527.    else
  528.       let rec aux = fun string ->
  529.          if String.contains string '!' then
  530.             ((String.get string ((String.index string '!')+1)) = (String.get lettre 1))||aux (String.sub string 1 ((String.length string)-1))
  531.             else false
  532.       in aux string;;
  533.  
  534.  
  535. let rec appartient firstLetterHtmp autreMots b =
  536.     match autreMots with
  537.     |[]-> b
  538.     |h2::t2-> if (containsLetter firstLetterHtmp h2)
  539.                 then appartient firstLetterHtmp t2 true
  540.                 else appartient firstLetterHtmp t2 b
  541. ;;
  542.  
  543. let rec partieCommuneAux l premierMot res = match premierMot with
  544.     ""-> res
  545.     |a-> if (appartient (firstLetter a) (List.tl l) false)
  546.             then partieCommuneAux l ( String.sub a (String.length (firstLetter a)) ((String.length a)-(String.length (firstLetter a))) )(*a-firstLetter a*) res^(firstLetter a)
  547.             else partieCommuneAux l ( String.sub a (String.length (firstLetter a)) ((String.length a)-(String.length (firstLetter a))) ) (*a-firstLetter a*) res
  548. ;;
  549.        
  550.  
  551. let partieCommune l = List.map (fun x -> partieCommuneAux x (List.hd x) "") l ;;
  552.  
  553. let rec listToStringSimplification  l = String.concat "+" (partieCommune l);;
  554.      
  555.      
  556.      
  557.      
  558.      
  559.      
  560.      
  561.      
  562.      
  563.      
  564.  
  565.          let get_all_coord = fun tableau -> List.flatten (List.map (fun x -> vary_line x ((List.length tableau)-1) (List.length tableau)) (vary_col (0,0) ((List.length(List.hd tableau))-1) (List.length(List.hd tableau))))
  566.    
  567.     let parcours = fun tableau list_def->
  568.         List.map (fun x-> explore x tableau list_def) (get_all_coord tableau);;
  569.      
  570.     (* exemples prérentrés *)
  571.         let tableauA = "!ab!c+ab!c+abc+a!bc" ;;
  572.         let tableauB = "!ab!c!d+ab!c!d+a!b!c!d+!ab!cd+ab!cd+a!b!cd+!abcd+abcd+!abc!d+abc!d" ;;
  573.         let tableauC = "!a!b!c!d+!ab!c!d+!ab!cd+!a!bcd+!abcd+a!b!c!d+a!bc!d";
  574.         let tableauD = "!a!b!c!d+a!b!c!d+!ab!cd+ab!cd+a!b!cd+!abcd+abcd+a!bcd+!a!bc!d+a!bc!d" ;;
  575.         let tableauCorners ="!a!b!c!d+a!b!c!d+!a!bc!d+a!bc!d" ;;
  576.      
  577.     (*procédure à compléter*)
  578.      
  579.     let main2 = fun string ->
  580.         let list_arg = lectureString string in
  581.             let list_word = decompose string in
  582.                 let tab_initial = init_tab list_arg 0 in
  583.                     let list_def = split list_arg in
  584.                         let tableau_de_karnaugh = create_table list_word list_def tab_initial in
  585.                             let list_group = parcours tableau_de_karnaugh list_def in
  586.                                 let list_group_filtered = filtrage (clear_list (removeVoid list_group)) in
  587.                                     listToStringSimplification (list_group_filtered);;
  588.     let main() = print_string (main2 (read_line()));;
  589.  
  590.  
  591.     main();;
Add Comment
Please, Sign In to add comment