Jump to content

Piprimes: Difference between revisions

Realize in F#
(Add Cowgol)
(Realize in F#)
Line 146:
16 17 17 18 18 18 18 19 19 20
20 20 20 21 21 21 21 21 21</pre>
=={{header|F_Sharp|F#}}==
<lang fsharp>
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
// PiPrimes: Nigel Galloway. April 5th., 2021
let fN=let i=primes32() in Seq.unfold(fun(n,g,l)->Some(l,if n=g then (n+1,Seq.head i,l+1) else (n+1,g,l)))(1,Seq.head i,0)
fN|>Seq.takeWhile((>)22)|>Seq.chunkBySize 20|>Seq.iter(fun n->Array.iter(printf "%2d ") n; printfn "")
</lang>
{{out}}
<pre>
0 0 1 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7 8
8 8 8 9 9 9 9 9 9 10 10 11 11 11 11 11 11 12 12 12
12 13 13 14 14 14 14 15 15 15 15 15 15 16 16 16 16 16 16 17
17 18 18 18 18 18 18 19 19 19 19 20 20 21 21 21 21 21 21
</pre>
=={{header|Fermat}}==
<lang fermat>n:=0; p:=0
2,172

edits

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