Multi-base primes: Difference between revisions
Content added Content deleted
(→{{header|Pascal}}: extended like raku and phix to base 62) |
(→{{header|Go}}: Generalized program to deal with any base up to 62. Added results for latter.) |
||
Line 280: | Line 280: | ||
var maxDepth = 6 |
var maxDepth = 6 |
||
var maxBase = 36 |
|||
var c = rcu.PrimeSieve(int(math.Pow( |
var c = rcu.PrimeSieve(int(math.Pow(float64(maxBase), float64(maxDepth))), true) |
||
var digits = "0123456789abcdefghijklmnopqrstuvwxyz" |
|||
var digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|||
var maxStrings [][][]int |
var maxStrings [][][]int |
||
var mostBases = -1 |
var mostBases = -1 |
||
Line 304: | Line 305: | ||
func process(indices []int) { |
func process(indices []int) { |
||
minBase := maxInt(2, maxSlice(indices)+1) |
minBase := maxInt(2, maxSlice(indices)+1) |
||
if |
if maxBase - minBase + 1 < mostBases { |
||
return // can't affect results so return |
return // can't affect results so return |
||
} |
} |
||
var bases []int |
var bases []int |
||
for b := minBase; b <= |
for b := minBase; b <= maxBase; b++ { |
||
n := 0 |
n := 0 |
||
for _, i := range indices { |
for _, i := range indices { |
||
Line 362: | Line 363: | ||
mostBases = -1 |
mostBases = -1 |
||
indices := make([]int, depth) |
indices := make([]int, depth) |
||
nestedFor(indices, |
nestedFor(indices, maxBase, 0) |
||
printResults() |
printResults() |
||
fmt.Println() |
fmt.Println() |
||
Line 390: | Line 391: | ||
6 character strings which are prime in most bases: 18 |
6 character strings which are prime in most bases: 18 |
||
441431 -> [5 8 9 11 12 14 16 17 19 21 22 23 26 28 30 31 32 33] |
441431 -> [5 8 9 11 12 14 16 17 19 21 22 23 26 28 30 31 32 33] |
||
</pre> |
|||
<br> |
|||
If we change maxBase to 62 and maxDepth to 5 in the above code, then the following results are reached in 0.5 and 19.2 seconds for 4 and 5 digit character strings, respectively: |
|||
<pre> |
|||
1 character strings which are prime in most bases: 60 |
|||
2 -> [3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62] |
|||
2 character strings which are prime in most bases: 31 |
|||
65 -> [7 8 9 11 13 14 16 17 18 21 22 24 27 28 29 31 32 37 38 39 41 42 43 44 46 48 51 52 57 58 59] |
|||
3 character strings which are prime in most bases: 33 |
|||
1l1 -> [22 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 45 46 48 51 52 53 54 57 58 59 60 61 62] |
|||
b9b -> [13 14 15 16 17 19 20 21 23 24 26 27 28 30 31 34 36 39 40 42 45 47 49 50 52 53 54 57 58 59 60 61 62] |
|||
4 character strings which are prime in most bases: 32 |
|||
1727 -> [8 9 11 12 13 15 16 17 19 20 22 23 24 26 27 29 31 33 36 37 38 39 41 45 46 48 50 51 57 58 60 61] |
|||
417b -> [12 13 15 16 17 18 19 21 23 25 28 30 32 34 35 37 38 39 41 45 48 49 50 51 52 54 56 57 58 59 61 62] |
|||
5 character strings which are prime in most bases: 30 |
|||
50161 -> [7 8 9 13 17 18 19 20 25 28 29 30 31 33 35 36 38 39 41 42 43 44 47 48 52 55 56 59 60 62] |
|||
</pre> |
</pre> |
||