Jump to content

Euclid-Mullin sequence: Difference between revisions

→‎{{header|F_Sharp|F#}}: Idiotmatically use an active pattern
(→‎{{header|F_Sharp|F#}}: Idiotmatically use an active pattern)
Line 21:
<lang fsharp>
//Euclid-Mullin sequence. Nigel Galloway: October 29th., 2021
let(|Prime|_|)(n,g)=if Open.Numeric.Primes.MillerRabin.IsProbablePrime &g then Some(n*g,n*g+1I) else None
open Open.Numeric.Primes
let n=Seq.unfold(fun(n,g)->match MillerRabin.IsProbablePrime &n,g with truePrime n->Some(g,(n*g,n*g+1I)) |_->let g=Open.Numeric.Primes.Extensions.PrimeExtensions.PrimeFactors g|>Seq.item 1 in Some(g,(n*g,n*g+1I)))(1I,2I)
n|>Seq.take 16|>Seq.iter(printfn "%A")
</lang>
2,172

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.