Guest User

Untitled

a guest
Oct 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. let rec sumList aList =
  2. match aList with
  3. | [] -> 0
  4. | head :: tail -> head + sumList tail
  5.  
  6. let minList aL =
  7. let h = List.head aL
  8. let rec min aList cur =
  9. match aList with
  10. | [] -> 0
  11. | head :: [] -> if head < cur then head else cur
  12. | head :: tail -> if head < cur then min tail head else min tail cur
  13. min aL h
  14.  
  15. let maxList aL =
  16. let h = List.head aL
  17. let rec max aList cur =
  18. match aList with
  19. | [] -> 0
  20. | head :: [] -> if head > cur then head else cur
  21. | head :: tail -> if head > cur then max tail head else max tail cur
  22. max aL h
  23.  
  24. let search aL elem =
  25. let rec searchList aList =
  26. match aList with
  27. | [] -> false
  28. | head :: [] -> if head = elem then true else false
  29. | head :: tail -> if head = elem then true else searchList tail
  30. searchList aL
  31.  
  32. let firstHalf aList =
  33. let rec dropLast = function
  34. | ([] | [_]), _ -> []
  35. | x, ([] | [_]) -> []
  36. | x::xt, y::ys::yt -> x :: dropLast (xt, yt)
  37. dropLast (aList, aList)
  38.  
  39. let x = firstHalf [0;1;2;3;4;5;6;7]
  40.  
  41. let a = [1;2;3;4;45;6;7;8;9;0;100]
  42.  
  43. let x = sumList a // 185
  44.  
  45. let y = minList a // 0
  46.  
  47. let z = maxList a // 100
  48.  
  49. let mu = search a 100 // True
  50.  
  51. let x = firstHalf [0;1;2;3;4;5;6;7] // [0; 1; 2; 3]
Add Comment
Please, Sign In to add comment