Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec tete = function
- []-> []
- |(elem::r)::reste -> elem::(tete reste)
- |_-> failwith "";;
- let rec reste = function
- []->[]
- |(elem::r)::rest->r::(reste rest)
- |_-> failwith "";;
- let rec trans matrice = match matrice with
- []->[]
- |[]::matrix -> trans matrix
- |_-> tete matrice ::(trans (reste matrice));;
- trans [[1;2];[7;3]];;
- let rec map f = function
- | []->[]
- | e::liste -> (f e)::(map f liste);;
- let prem = function
- []-> failwith ""
- |e::reste -> e;;
- let tete2 liste = map prem liste;;
- let rest = function
- []-> failwith ""
- |e::reste -> reste;;
- let reste2 liste = map rest liste;;
- let rec lzero n = if n = 0 then [] else 0::(lzero (n-1));;
- let zero n = map(fun _-> lzero n) (lzero n);;
- let rec unite = function | 0 -> []
- | 1 -> [[1]]
- | x -> (1::(premier (zero (x-1))))::(map (fun liste-> 0::liste) (unite (x-1)));;
- let rec map2 = fun fbin -> fun l1 -> fun l2 -> match(l1,l2) with
- |x1::reste1,y1::reste2 -> (fbin x1 y1)::(map2 fbin reste1 reste2)
- |_-> failwith "error";;
- let premier = function | [] -> failwith("Liste vide") | e::liste -> e;;
- let empute = function | [] -> failwith("Liste vide") | e::liste -> liste;;
- let somlig = map2 (+) ;;
- let add = map2 somlig;;
- let rec prodligcol = fun lig -> fun col -> match col with
- []->failwith ""
- |e::rst -> (e * (premier lig))::(prodligcol (empute lig) rst);;
- let rec prodligtmat = fun lig -> fun matCol -> match matCol with
- []->failwith ""
- |col::rstMat -> (prodligcol lig col)::(prodligtmat lig matCol);;
- let prodligtmat2 lig matCol = map (prodligcol lig) matCol
- let rec prod ml mc = match ml with
- [] -> []
- |l::ml1 -> (prodligtmat l mc)::(prod ml1 mc);;
- ____________________________________________________________________________________________________
- type elem = Obstacle | Objet | Vide;;
- type prop = Contient of elem | PinceVide | Conjonction of prop * prop | Negation of prop;;
- let it_prop = fun fCont -> fun fPinceVide ->fun fConj ->fun fNegat->
- let rec trait = function
- |Contient(e) -> fCont e
- |PinceVide -> fPinceVide
- |Conjonction(p1,p2) -> fConj p1 p2 (trait p1) (trait p2)
- |Negation(p) -> fNegat p (trait p)
- in trait ;;
- let terme = Conjonction(Contient(Objet) ,PinceVide) ;;
- type plateau = (int * int) -> elem;;
- type etat = Etat of plateau * (int * int) * bool * (int*int);;
- let p1 = Objet ;;
- let getpl = function Etat(pl,_,_,_) -> pl
- and getpos = function Etat(_,pos,_,_) -> pos
- and getpince = function Etat(_,_,pince,_) -> pince
- and getv = function Etat(_,_,_,v) -> v;;
- let rec eval = fun etat -> fun prop -> match prop with
- |Contient elem -> (getpl etat) (getpos etat) = elem
- |PinceVide -> getpince etat
- |Conjonction(p1,p2) -> eval etat p1 && eval etat p2
- |Negation (p) -> not ( eval etat p);;
- (*let eval = fun etat -> fun prop ->
- it_prop (fun elem -> elem = (getpl etat) (getpos etat))*)
- let prendreCase = fun element -> match element with
- |Obstacle ->failwith "obstacle"
- |Objet -> Vide
- |Vide -> failwith"vide";;
- let prendre = fun plat -> fun (x,y) -> (fun (z,w) -> if z=x && w=y then prendreCase (plat (z,w)) else plat(z,w));;
- let etatPrendre = function Etat(plateau, pos, pince, vect) -> Etat((prendre plateau pos), pos, false, vect);;
- let etatAvancer = function Etat(plateau, (x,y), pince, (z,t)) -> if plateau (x+z, y+t) = Obstacle then failwith"obstacle"
- else Etat(plateau, (x+z, y+t), pince, (z,t));;
- type commande = Prendre | Poser | Tourner of int | Avancer | Exec of commande * bool | ExecList of commande list;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement