Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let avg (lista:int list) =
- let rec sum lista suma =
- match lista with
- | [] -> suma
- | head :: tail -> sum tail (suma + head)
- let suma = sum lista 0
- let rec length lista =
- match lista with
- | [] -> 0
- | head :: tail -> 1 + length tail
- let srednia = length lista
- suma/srednia
- avg [2; 15; 1; 2]
- let minMax (lista:int list) =
- let rec findMax lista max =
- match lista with
- | [] -> max
- | head :: tail -> findMax tail (if head > max then head else max)
- let rec findMin lista min =
- match lista with
- | [] -> min
- | head :: tail -> findMin tail (if head < min then head else min)
- (findMax lista -9999, findMin lista 9999)
- minMax [6; -2; 3; 4; 5]
- let usunWiekszeNizSrednia (lista:int list) =
- let srednia = avg lista
- let rec remove list=
- match list with
- | [] -> []
- | x :: xs ->
- let element = remove xs
- if x > srednia then element else x::element
- remove lista
- usunWiekszeNizSrednia [2; 15; 1; 2; 100; 100;]
- let parzystePodzielnePrzez3 (lista:int list) =
- let rec parzyste lista licznik =
- match lista with
- | [] -> licznik
- | head :: tail -> parzyste tail (if head % 2 = 0 then (licznik + 1) else licznik)
- let rec podzielnePrzez3 lista licznik =
- match lista with
- | [] -> licznik
- | head :: tail -> podzielnePrzez3 tail (if head % 3 = 0 then (licznik + 1) else licznik)
- (parzyste lista 0, podzielnePrzez3 lista 0)
- parzystePodzielnePrzez3 [1; 2; 3; 4; 5; 6; 7; 8; 9; 12]
- let listaPrzystychIPodzielnychPrzez3 (lista:int list) =
- let lPodzielne = [];
- let rec dodajDoListy lista element =
- match lista with
- | [] -> [element]
- | head :: tail -> (head::element::tail)
- let rec parzyste (lista:int list) (lParzyste:int list) =
- match lista with
- | [] -> []
- | head :: tail -> if head % 2 = 0
- then
- parzyste tail (List.append lParzyste [head])
- else
- parzyste tail lParzyste
- parzyste lista ([]:int list)
- listaPrzystychIPodzielnychPrzez3 [1; 2; 3; 4; 5; 6; 7; 8; 9; 12]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement