Anti-primes: Difference between revisions

Line 216:
 
=={{header|F_Sharp|F#}}==
===The Function===
{{incorrect|F_SharpTask asks for a specific number of terms that would stop excessive output - check other solutions and task description if in doubt.}};The Function:
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<lang fsharp>
Line 226:
let fL,_=Seq.concat(Seq.scan(fun n g->fE n (fG g)) (seq[(2147483647,1,1I)]) fI)|>List.ofSeq|>List.sortBy(fun(_,_,n)->n)|>List.fold(fun ((a,b) as z) (_,n,g)->if n>b then ((n,g)::a,n) else z) ([],0)
</lang>
;===The Task:===
 
<lang fsharp>
;The Task:
printfn "The first 20 anti-primes are :-"; for (_,g) in (List.rev fL)|>List.take 20 do printfn "%A" g
</lang>
{{out}}
<pre>
The first 20 anti-primes are :-
1
2
4
6
12
24
36
48
60
120
180
240
360
720
840
1260
1680
2520
5040
7560
</pre>
===Extra Credit===
<lang fsharp>
printfn "There are %d anti-primes less than %A:-" (List.length fL) N; for (n,g) in (List.rev fL) do printfn "%A has %d dividers" g n
Line 233 ⟶ 260:
{{out}}
<pre style="height:35ex">
Real: 00:00:10.683, CPU: 00:00:10.880, GC gen0: 1394, gen1: 1
There are 245 anti-primes less than 200000000000000000000000000:-
1 has 1 dividers
2,172

edits