Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Ascending-primes/Go/ascending-primes.go
Normal file
43
Task/Ascending-primes/Go/ascending-primes.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"rcu"
|
||||
"sort"
|
||||
)
|
||||
|
||||
var ascPrimesSet = make(map[int]bool) // avoids duplicates
|
||||
|
||||
func generate(first, cand, digits int) {
|
||||
if digits == 0 {
|
||||
if rcu.IsPrime(cand) {
|
||||
ascPrimesSet[cand] = true
|
||||
}
|
||||
return
|
||||
}
|
||||
for i := first; i < 10; i++ {
|
||||
next := cand*10 + i
|
||||
generate(i+1, next, digits-1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for digits := 1; digits < 10; digits++ {
|
||||
generate(1, 0, digits)
|
||||
}
|
||||
le := len(ascPrimesSet)
|
||||
ascPrimes := make([]int, le)
|
||||
i := 0
|
||||
for k := range ascPrimesSet {
|
||||
ascPrimes[i] = k
|
||||
i++
|
||||
}
|
||||
sort.Ints(ascPrimes)
|
||||
fmt.Println("There are", le, "ascending primes, namely:")
|
||||
for i := 0; i < le; i++ {
|
||||
fmt.Printf("%8d ", ascPrimes[i])
|
||||
if (i+1)%10 == 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue