Rare numbers: Difference between revisions

Content deleted Content added
Realize in F# : Solution in less than 1min.
Line 29:
 
=={{header|F_Sharp|F#}}==
===;The Function===:
This solution demonstrates the concept described in [[Talk:Rare_numbers#30_mins_not_30_years]]. It uses [[Cartesian_product_of_two_or_more_lists#Extra_Credit]]
<lang fsharp>
Line 42:
l|>Seq.map(fun n->Seq.fold(fun(n,g) (n',g')->(n+n',g+g'))(0L,0L) n)|>Seq.filter(fun(n,g)->g>(pown 10L (a-1)) && izPS(n+g))
</lang>
 
===;The Task===
<lang fsharp>
[2..12]|>Seq.collect rN |> Seq.iter(printfn "%A")
Line 58 ⟶ 59:
Real: 00:00:58.835, CPU: 00:01:00.421, GC gen0: 3220, gen1: 441, gen2: 16
</pre>
 
=={{header|Go}}==
As in the case of the REXX entry, this takes into account all the hints within Shyam Sunder Gupta's webpage. It also makes use of his observation that no rare number below 10^20 ends in 3 and uses a bit arithmetic trick to further filter out numbers that cannot be perfect squares and thereby avoid the expensive math.Sqrt operation.