Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Semiprime/F-Sharp/semiprime.fs
Normal file
15
Task/Semiprime/F-Sharp/semiprime.fs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
let isSemiprime (n: int) =
|
||||
let rec loop currentN candidateFactor numberOfFactors =
|
||||
if numberOfFactors > 2 then numberOfFactors
|
||||
elif currentN = candidateFactor then numberOfFactors+1
|
||||
elif currentN % candidateFactor = 0 then loop (currentN/candidateFactor) candidateFactor (numberOfFactors+1)
|
||||
else loop currentN (candidateFactor+1) numberOfFactors
|
||||
if n < 2 then false else 2 = loop n 2 0
|
||||
|
||||
seq { 1 .. 100 } |> Seq.choose (fun n -> if isSemiprime n then Some(n) else None)
|
||||
|> Seq.toList |> printfn "%A"
|
||||
|
||||
seq { 1675 .. 1680 }
|
||||
|> Seq.choose (fun n -> if isSemiprime n then Some(n) else None)
|
||||
|> Seq.toList
|
||||
|> printfn "%A"
|
||||
Loading…
Add table
Add a link
Reference in a new issue