F# finding only prime numbers -


i'm new f# please bear me. problem have i'm trying find prime numbers.

i've write code:

  let isprime n =     let rec check =     > n/2 || (n % <> 0 && check (i + 1))        check 2;;  let listnums = list.filter isprime >> list.length;;   let nums = [ 16; 17; 3; 4; 2; 5; 11; 6; 7; 18; 13; 14; ];;  let countprimes (x:int) = x |> list.ofseq |> listnums;; 

trying call

countprimes nums;; 

but failed message:

the type 'int' not compatible type 'seq<'a>' 

any appreciated

you not need countprimes separately. enough remove , work:

let isprime n =     let rec check =         > n/2 || (n % <> 0 && check (i + 1))     check 2  let nums = [ 16; 17; 3; 4; 2; 5; 11; 6; 7; 18; 13; 14; ]  let listprime lst =     lst |> list.filter isprime  nums |> listprime |> printfn "%a" 

out: [17; 3; 2; 5; 11; 7; 13]

link: https://dotnetfiddle.net/nvxwz5


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -