Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Etat == int;;
- type automate = {
- initial : Etat;
- delta : Etat -> char -> Etat;
- vals : Etat -> int;
- };;
- (*Question 1*)
- let execute a m =
- let e = ref(a.initial) in
- for i = 0 to string_length(m) - 1 do
- e := a.delta !e (m.[i]);
- done;
- a.vals !e;;
- let valsExemple e = match e with
- | 4 -> 1;
- | n -> 0;;
- let deltaExemple e c = match e, c with
- | 1, `a` -> 2;
- | 2, `a` -> 3;
- | 3, `a` -> 3;
- | 3, `b` -> 4;
- | 4, `a` -> 3;
- | n, c -> -1;;
- let exemple = { initial = 1; delta = deltaExemple; vals = valsExemple };;
- let rec int2string n =
- let resultat = ref("") in
- let refn = ref(n) in
- while !refn > 0 do
- if !refn mod 2 = 0 then
- resultat := !resultat ^ (make_string 1 `0`)
- else
- resultat := !resultat ^ (make_string 1 `1`);
- refn := !refn / 2;
- done;
- let temp = (make_string (string_length !resultat) `0`) in
- for i = 0 to string_length(!resultat) - 1 do
- temp.[i] <- !resultat.[(string_length !resultat) - 1 - i];
- done;
- temp;;
- let deltaDiv3 e c = match e, c with
- | 0, `0` -> 0
- | 0, `1` -> 1
- | 1, `1` -> 0
- | 1, `0` -> 2
- | 2, `0` -> 1
- | 2, `1` -> 2
- | e, c -> -1;;
- let valsDiv3 e = match e with
- | 0 -> 1
- | n -> 0;;
- let div3 = { initial = 0; delta = deltaDiv3; vals = valsDiv3 };;
- print_int(execute div3 (int2string 9));;
- let rec insere e l = match e, l with
- | e, [] -> [e]
- | e, t::q ->
- if t < e then
- t::e::q
- else
- t::(insere e q);;
- let rec egal E1 E2 = match E1, E2 with
- | [], [] -> true
- | l, [] -> false
- | [], l -> false
- | t1::q1, t2::q2 -> (t1 = t2 && egal q1 q2);;
- let rec estDans e l = match l with
- | [] -> false
- | t::q -> t = e || (e < t && estDans e q);;
- type afnd = {
- ei : Etat list;
- transitions : (Etat * char * Etat) list;
- vals : Etat -> int
- };;
- let etatsAFND a =
- let insererSiNonPresent liste element = if !estDans
- let rec tousLesEtats liste acc = match liste with
- | [] -> acc
- | t::q ->
Advertisement
Add Comment
Please, Sign In to add comment