Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.19 KB | None | 0 0
  1. let rec zlicz(str : string, ch : char) =
  2.     match str.Length with
  3.     | 0 -> 0
  4.     | _ ->  if(str.[0] = ch) then zlicz(str.[1..], ch) + 1
  5.             else zlicz(str.[1..], ch)
  6.  
  7. let rec sumujliste(lista: float list) =
  8.     match lista with
  9.     | [] -> 0.0
  10.     | head::tail -> head + sumujliste(tail)
  11.  
  12.  
  13. // Funkcja działa jeśli w pierwszej liście elementy
  14. // się nie powtarzają. Jeśli się powtarzają to
  15. // wypisze wszystkie powtórzenia.
  16. // W drugiej liście mogą się powtarzać.
  17. let rec common(lhs: int list, rhs: int list) =
  18.     match lhs with
  19.     | [] -> []
  20.     | head::tail -> if(List.exists(fun elem -> elem = head) rhs)
  21.                     then List.append (common(tail, rhs)) [head]
  22.                     else common(tail, rhs)
  23.    
  24. [<EntryPoint>]
  25. let main argv =
  26.     let result = zlicz("string do zliczenia", 'i')
  27.     printfn "%A" result
  28.  
  29.     let wyjdziePiec = [1.2; 2.3; 0.5; 0.8; 0.2]
  30.     let result2 = sumujliste(wyjdziePiec)
  31.     printfn "%A" result2
  32.  
  33.     let pierwsza = [1; 5; 8; 4; 6]
  34.     let druga = [4; 8; 9; 10]
  35.     let wspolna = common(pierwsza, druga)
  36.     printfn "%A" wspolna
  37.  
  38.     System.Console.ReadKey() |> ignore
  39.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement