Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. let rec tete = function
  2. []-> []
  3. |(elem::r)::reste -> elem::(tete reste)
  4. |_-> failwith "";;
  5.  
  6. let rec reste = function
  7. []->[]
  8. |(elem::r)::rest->r::(reste rest)
  9. |_-> failwith "";;
  10.  
  11.  
  12. let rec trans matrice = match matrice with
  13. []->[]
  14. |[]::matrix -> trans matrix
  15. |_-> tete matrice ::(trans (reste matrice));;
  16.  
  17. trans [[1;2];[7;3]];;
  18.  
  19. let rec map f = function
  20. | []->[]
  21. | e::liste -> (f e)::(map f liste);;
  22.  
  23. let prem = function
  24. []-> failwith ""
  25. |e::reste -> e;;
  26.  
  27. let tete2 liste = map prem liste;;
  28.  
  29. let rest = function
  30. []-> failwith ""
  31. |e::reste -> reste;;
  32.  
  33. let reste2 liste = map rest liste;;
  34.  
  35. let rec lzero n = if n = 0 then [] else 0::(lzero (n-1));;
  36. let zero n = map(fun _-> lzero n) (lzero n);;
  37. let rec unite = function | 0 -> []
  38. | 1 -> [[1]]
  39. | x -> (1::(premier (zero (x-1))))::(map (fun liste-> 0::liste) (unite (x-1)));;
  40.  
  41. let rec map2 = fun fbin -> fun l1 -> fun l2 -> match(l1,l2) with
  42. |x1::reste1,y1::reste2 -> (fbin x1 y1)::(map2 fbin reste1 reste2)
  43. |_-> failwith "error";;
  44.  
  45. let premier = function | [] -> failwith("Liste vide") | e::liste -> e;;
  46. let empute = function | [] -> failwith("Liste vide") | e::liste -> liste;;
  47.  
  48.  
  49. let somlig = map2 (+) ;;
  50.  
  51. let add = map2 somlig;;
  52.  
  53. let rec prodligcol = fun lig -> fun col -> match col with
  54. []->failwith ""
  55. |e::rst -> (e * (premier lig))::(prodligcol (empute lig) rst);;
  56.  
  57. let rec prodligtmat = fun lig -> fun matCol -> match matCol with
  58. []->failwith ""
  59. |col::rstMat -> (prodligcol lig col)::(prodligtmat lig matCol);;
  60.  
  61. let prodligtmat2 lig matCol = map (prodligcol lig) matCol
  62.  
  63. let rec prod ml mc = match ml with
  64. [] -> []
  65. |l::ml1 -> (prodligtmat l mc)::(prod ml1 mc);;
  66. ____________________________________________________________________________________________________
  67. type elem = Obstacle | Objet | Vide;;
  68. type prop = Contient of elem | PinceVide | Conjonction of prop * prop | Negation of prop;;
  69. let it_prop = fun fCont -> fun fPinceVide ->fun fConj ->fun fNegat->
  70. let rec trait = function
  71. |Contient(e) -> fCont e
  72. |PinceVide -> fPinceVide
  73. |Conjonction(p1,p2) -> fConj p1 p2 (trait p1) (trait p2)
  74. |Negation(p) -> fNegat p (trait p)
  75. in trait ;;
  76.  
  77. let terme = Conjonction(Contient(Objet) ,PinceVide) ;;
  78. type plateau = (int * int) -> elem;;
  79. type etat = Etat of plateau * (int * int) * bool * (int*int);;
  80.  
  81. let p1 = Objet ;;
  82.  
  83. let getpl = function Etat(pl,_,_,_) -> pl
  84. and getpos = function Etat(_,pos,_,_) -> pos
  85. and getpince = function Etat(_,_,pince,_) -> pince
  86. and getv = function Etat(_,_,_,v) -> v;;
  87. let rec eval = fun etat -> fun prop -> match prop with
  88. |Contient elem -> (getpl etat) (getpos etat) = elem
  89. |PinceVide -> getpince etat
  90. |Conjonction(p1,p2) -> eval etat p1 && eval etat p2
  91. |Negation (p) -> not ( eval etat p);;
  92.  
  93. (*let eval = fun etat -> fun prop ->
  94. it_prop (fun elem -> elem = (getpl etat) (getpos etat))*)
  95. let prendreCase = fun element -> match element with
  96. |Obstacle ->failwith "obstacle"
  97. |Objet -> Vide
  98. |Vide -> failwith"vide";;
  99.  
  100. let prendre = fun plat -> fun (x,y) -> (fun (z,w) -> if z=x && w=y then prendreCase (plat (z,w)) else plat(z,w));;
  101. let etatPrendre = function Etat(plateau, pos, pince, vect) -> Etat((prendre plateau pos), pos, false, vect);;
  102. let etatAvancer = function Etat(plateau, (x,y), pince, (z,t)) -> if plateau (x+z, y+t) = Obstacle then failwith"obstacle"
  103. else Etat(plateau, (x+z, y+t), pince, (z,t));;
  104. 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