SHARE
TWEET

Untitled

a guest Aug 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. let usagers_aller = [
  3. creer_usager "camille" 'A' 'D' 1;
  4. creer_usager "antoine" 'B' 'D' 3;
  5. creer_usager "hubert" 'C' 'E' 2;
  6. creer_usager "felix" 'D' 'F' 4;
  7. creer_usager "yassine" 'E' 'F' 5;
  8. creer_usager "ali" 'A' 'C' 5;
  9. creer_usager "clemence" 'B' 'C' 3;
  10. creer_usager "fatima" 'C' 'D' 4;
  11. creer_usager "franz" 'B' 'E' 4;
  12. creer_usager "perrine" 'C' 'F' 2;
  13. ];;
  14.  
  15.  
  16. let usagers_aller_retour = [
  17. creer_usager "thomas" 'F' 'A' 3;
  18. creer_usager "seb" 'E' 'B' 2;
  19. creer_usager "camille" 'A' 'D' 1;
  20. creer_usager "antoine" 'B' 'D' 3;
  21. creer_usager "hubert" 'C' 'E' 2;
  22. creer_usager "floriane" 'D' 'C' 1;
  23. creer_usager "laure" 'C' 'B' 5;
  24. creer_usager "fernando" 'B' 'A' 5;
  25. creer_usager "anabelle" 'F' 'E' 5;
  26. creer_usager "felix" 'D' 'F' 4;
  27. creer_usager "yassine" 'E' 'F' 5;
  28. creer_usager "romain" 'E' 'B' 4;
  29. creer_usager "alexis" 'D' 'C' 2;
  30. creer_usager "ali" 'A' 'C' 5;
  31. creer_usager "clemence" 'B' 'C' 3;
  32. creer_usager "amel" 'D' 'B' 4;
  33. creer_usager "fatima" 'C' 'D' 4;
  34. creer_usager "franz" 'B' 'E' 4;
  35. creer_usager "perrine" 'C' 'F' 2;
  36. creer_usager "delphine" 'D' 'A' 2;
  37. ];;
  38.  
  39. let ligne_de_tram = 'A'::'B'::'C'::'D'::'E'::'F'::[];;
  40.  
  41. let rec list_last l =
  42.     match l with
  43.     |[]->failwith "liste vide"
  44.     |h::[]->h
  45.     |h::t-> list_last t
  46. ;;
  47.  
  48. let rec terminus l =
  49.     match l with
  50.     |[]->false
  51.     |h::[]->true
  52.     |h::t->false
  53. ;;
  54.  
  55. let rec incident c l =
  56.     match l with
  57.     |[]->[]
  58.     |h::t-> if c=h
  59.         then
  60.             []
  61.         else
  62.             h::(incident c t)
  63. ;;
  64.  
  65. let listetarifs = 1.40::1.30::1.20::0.90::0.70::[];;
  66.  
  67. let rec prix i l =
  68.     match l with
  69.     |[]->failwith "Pas de prix"
  70.     |h::t-> if i-1 = 0
  71.         then
  72.             h
  73.         else
  74.             if i-1 > 0
  75.                 then
  76.                     prix (i-1) t
  77.                 else
  78.                     failwith "Pas de prix"
  79. ;;
  80.  
  81. type usager =
  82.     {
  83.     nom : string;
  84.     depart : char;
  85.     arrivee : char;
  86.     tarif : int
  87.     }
  88. ;;
  89.  
  90. let creer_usager nm dp ar tr =
  91.     {
  92.     nom = nm;
  93.     depart = dp;
  94.     arrivee = ar;
  95.     tarif = tr
  96.     }
  97. ;;
  98.  
  99. let rec compter_abonnes l =
  100.     match l with
  101.     |[]->0
  102.     |h::t-> (compter_abonnes t) + if h.tarif = 5
  103.                 then
  104.                     1usagers_aller
  105.                 else
  106.                     0
  107. ;;
  108.  
  109. let rec somme_des_prix l =
  110.     match l with
  111.     |[]-> 0.
  112.     |h::t-> (prix h.tarif listetarifs) +. (somme_des_prix t)
  113. ;;
  114.  
  115. type tramway =
  116.     {
  117.     ligne : char list;
  118.     dedans : usager list;
  119.     dehors : usager list
  120.     }
  121. ;;
  122.  
  123. let creer_tramway ln dd dh =
  124.     {
  125.     ligne = ln;
  126.     dedans = dd;
  127.     dehors = dh
  128.     }
  129. ;;
  130.  
  131. let tram_vide = creer_tramway ligne_de_tram [] usagers_aller;;
  132.  
  133. let tram_plein = creer_tramway ligne_de_tram usagers_aller [];;
  134.  
  135. let remdebut l =
  136.     match l with
  137.     |[]->failwith "Pas possible"
  138.     |h::t->t
  139. ;;
  140.  
  141. let avancer_tram t =
  142.     creer_tramway (remdebut t.ligne) t.dedans t.dehors
  143. ;;
  144.  
  145. let debut l =
  146.     match l with
  147.     |[]->failwith "Pas possible"
  148.     |h::t->h
  149. ;;
  150.  
  151. let monter trm =
  152.     let test u = (u.depart=(debut trm.ligne)) in
  153.     let test2 u = not (u.depart=(debut trm.ligne)) in
  154.     let usagers_qui_montent = List.filter test trm.dehors in
  155.     creer_tramway trm.ligne (trm.dedans @ usagers_qui_montent) (List.filter test2 trm.dehors)
  156. ;;             
  157.  
  158. let descendre trm =
  159.     let test u = (u.arrivee=(debut trm.ligne)) in
  160.     let test2 u = not (u.arrivee=(debut trm.ligne)) in
  161.     let usagers_qui_descendent = List.filter test trm.dehors in
  162.     creer_tramway trm.ligne (List.filter test2 trm.dedans) (trm.dehors @ usagers_qui_descendent)
  163. ;;             
  164.  
  165. let deplacer trm = descendre (avancer_tram (monter (trm) ) );;
  166.  
  167. let sens_usager u =
  168.     u.depart<u.arrivee
  169. ;;
  170.  
  171. let sens_tram trm =
  172.     match trm.ligne with
  173.     |[] -> true
  174.     |_::_ -> true
  175.     |h1::h2::_ -> (h1<h2)
  176. ;;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top