Fortunate numbers: Difference between revisions

Added Go
(→‎{{header|Raku}}: Add a Raku example)
(Added Go)
Line 21:
* [[oeis:A046066]] Fortunate numbers, sorted with duplicates removed
<br><br>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<lang go>package main
 
import (
"fmt"
"math/big"
"rcu"
"sort"
)
 
func main() {
primes := rcu.Primes(379)
primorial := big.NewInt(1)
var fortunates []int
bPrime := new(big.Int)
for _, prime := range primes {
bPrime.SetUint64(uint64(prime))
primorial.Mul(primorial, bPrime)
for j := 3; ; j += 2 {
jj := big.NewInt(int64(j))
bPrime.Add(primorial, jj)
if bPrime.ProbablyPrime(5) {
fortunates = append(fortunates, j)
break
}
}
}
m := make(map[int]bool)
for _, f := range fortunates {
m[f] = true
}
fortunates = fortunates[:0]
for k := range m {
fortunates = append(fortunates, k)
}
sort.Ints(fortunates)
fmt.Println("After sorting, the first 50 distinct fortunate numbers are:")
for i, f := range fortunates[0:50] {
fmt.Printf("%3d ", f)
if (i+1)%10 == 0 {
fmt.Println()
}
}
fmt.Println()
}</lang>
 
{{out}}
<pre>
After sorting, the first 50 distinct fortunate numbers are:
3 5 7 13 17 19 23 37 47 59
61 67 71 79 89 101 103 107 109 127
151 157 163 167 191 197 199 223 229 233
239 271 277 283 293 307 311 313 331 353
373 379 383 397 401 409 419 421 439 443
</pre>
 
=={{header|Raku}}==
9,476

edits