You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
873 B
Forth

let containsAs (s : string) =
String.filter (fun c -> c = 'a') s |> String.length
let numOfStringsContainingAs (str : string []) =
str
|> Array.map (fun s -> containsAs(s))
|> Array.sum
printfn "%A" (numOfStringsContainingAs [|"ciao";"come";"va"|])
printfn "%A" (numOfStringsContainingAs [|"ciaaao";"come";"va"|])
let numeroPippo x = if x%3 = 1 then Some(x) else None
let parolaPippo x = if x = "pippo" then Some(x) else None
let isPippo (x : option<'a>) =
match x with
| Some(x) -> true
| None -> false
printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a";"a"|] |> numeroPippo))
printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a"|] |> numeroPippo))
printfn "%b" (isPippo(parolaPippo("pipo")))
printfn "%b" (isPippo(parolaPippo("pippo")))
let s = Seq.initInfinite (fun s -> s*s)
printfn "%A" (Seq.toList (Seq.take 10 s))