Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type car = string*string*int
- let car1 = ("Opel", "astra", 1999)
- let car2 = ("Renault", "megane", 2004)
- let car3 = ("Opel", "corsa", 2009)
- let car4 = ("Nissan", "micra", 2004)
- let car5 = ("Opel", "corsa", 2009)
- let car6 = ("Nissan", "micra", 2004)
- let carList = [car1;car2;car3;car4;car5;car6]
- let apperiance cars productionYear =
- let rec countApperiance filteredCars result =
- match filteredCars with
- | [] -> result
- | (cars1,cars2,cars3)::t ->
- let rec countAndRemove currentCars resultCars (x1,x2,x3) count =
- match currentCars with
- | [] -> (resultCars, count)
- | (h1,h2,h3)::t -> if(h1=x1 && h2=x2) then countAndRemove t resultCars (x1,x2,x3) (count+1)
- else countAndRemove t ((h1,h2,h3)::resultCars) (x1,x2,x3) count
- in let (l1,a1) = countAndRemove filteredCars [] (cars1,cars2,cars3) 0
- in countApperiance l1 ((cars1,(cars2,a1))::result)
- in countApperiance (List.filter (function (x,y,z)->z==productionYear) cars) [];;
- apperiance carList 2004;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement