Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec zlicz(str : string, ch : char) =
- match str.Length with
- | 0 -> 0
- | _ -> if(str.[0] = ch) then zlicz(str.[1..], ch) + 1
- else zlicz(str.[1..], ch)
- let rec sumujliste(lista: float list) =
- match lista with
- | [] -> 0.0
- | head::tail -> head + sumujliste(tail)
- // Funkcja działa jeśli w pierwszej liście elementy
- // się nie powtarzają. Jeśli się powtarzają to
- // wypisze wszystkie powtórzenia.
- // W drugiej liście mogą się powtarzać.
- let rec common(lhs: int list, rhs: int list) =
- match lhs with
- | [] -> []
- | head::tail -> if(List.exists(fun elem -> elem = head) rhs)
- then List.append (common(tail, rhs)) [head]
- else common(tail, rhs)
- [<EntryPoint>]
- let main argv =
- let result = zlicz("string do zliczenia", 'i')
- printfn "%A" result
- let wyjdziePiec = [1.2; 2.3; 0.5; 0.8; 0.2]
- let result2 = sumujliste(wyjdziePiec)
- printfn "%A" result2
- let pierwsza = [1; 5; 8; 4; 6]
- let druga = [4; 8; 9; 10]
- let wspolna = common(pierwsza, druga)
- printfn "%A" wspolna
- System.Console.ReadKey() |> ignore
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement