Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.91 KB | None | 0 0
  1. let two () =
  2.   let rec largestCast xs movies maximum =
  3.     match xs with
  4.     |[] -> movies
  5.     |x :: xs ->
  6.       match x with (movie, cast) ->
  7.       match (compare (List.length cast) maximum) with
  8.       |1 -> largestCast xs (movie :: []) (List.length cast)
  9.       |0 -> largestCast xs (movie :: cast) maximum
  10.       | -1 -> largestCast xs movies maximum
  11.       |_ -> failwith "How tf did you get here what"
  12.   in
  13.   largestCast (Map.bindings fcMap) [] 0
  14.  
  15. let _ =
  16. let rec printList xs =
  17.   match xs with
  18.   | [] -> ()
  19.   | x :: xs ->
  20.     Code.pfmt "%s\n" x
  21.   ; printList xs
  22.   in
  23.   let ls = two ()
  24.   in
  25.   Code.pfmt "The movies with the largest cast are the following: \n"; (printList ls)
  26.  
  27.  
  28.  
  29.  
  30. let five () = let bind = Map.bindings fcMap in
  31.   let rec exists key ls =
  32.     match ls with
  33.     |[]-> false
  34.     |l::ls ->
  35.       match (key = l) with
  36.       |true -> true
  37.       |false -> exists key ls
  38. in
  39.   let rec helperFive ls actor movies =
  40.     match ls with
  41.     |[] -> movies
  42.     |l::ls ->
  43.       match l with (key, actors) ->
  44.       match (exists actor actors) with
  45.       |false -> helperFive ls actor movies
  46.       |true -> helperFive ls actor (movies ^ ", " ^ key)
  47.   in
  48.   helperFive bind "Owen Wilson" ""
  49.  
  50. let _ =
  51.   let str = five ()
  52.   in
  53.   Code.pfmt "Movies with Owen are as following%s." str; Code.pfmt "\n"
  54.  
  55.  
  56.  
  57. let nine () =
  58.   let rec largestMovies xs actors maximum =
  59.     match xs with
  60.     |[] -> actors
  61.     |x :: xs ->
  62.       match x with (actor, movie) ->
  63.       match (compare (List.length movie) maximum) with
  64.       |1 -> largestMovies xs (actor :: []) (List.length movie)
  65.       |0 -> largestMovies xs (actor :: actors) maximum
  66.       | -1 -> largestMovies xs actors maximum
  67.       |_ -> failwith "How tf did you get here what"
  68.   in
  69.   largestMovies (Map.bindings afMap) [] 0
  70.  
  71. let _ =
  72.   let ls = nine ()
  73.   in
  74.   Code.pfmt "The Actors with the most Movies done are the following: \n"; (printList ls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement