Advertisement
Guest User

Untitled

a guest
May 14th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.86 KB | None | 0 0
  1. // --------------------------- 1
  2. let avg (lista:int list) =
  3.     let rec sum lista suma =
  4.         match lista with
  5.         |  [] -> suma
  6.         |  head :: tail -> sum tail (suma + head)
  7.     let suma = sum lista 0
  8.    
  9.     let rec length lista =
  10.         match lista with
  11.         | [] -> 0
  12.         | head :: tail -> 1 + length tail
  13.  
  14.     let srednia = length lista
  15.     suma/srednia
  16.  
  17. avg [2; 15; 1; 2]
  18.  
  19. // ------------------------------ 2
  20. let minMax (lista:int list) =
  21.     let rec findMax lista max =
  22.         match lista with
  23.         | [] -> max
  24.         | head :: tail -> findMax tail (if head > max then head else max)
  25.  
  26.     let rec findMin lista min =
  27.         match lista with
  28.         | [] -> min
  29.         | head :: tail -> findMin tail (if head < min then head else min)
  30.  
  31.     (findMax lista -9999, findMin lista 9999)
  32.    
  33.  
  34. minMax [6; -2; 3; 4; 5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement