How to resolve the algorithm Repunit primes step by step in the Wren programming language
How to resolve the algorithm Repunit primes step by step in the Wren programming language
Table of Contents
Problem Statement
Repunit is a portmanteau of the words "repetition" and "unit", with unit being "unit value"... or in laymans terms, 1. So 1, 11, 111, 1111 & 11111 are all repunits. Every standard integer base has repunits since every base has the digit 1. This task involves finding the repunits in different bases that are prime. In base two, the repunits 11, 111, 11111, 1111111, etc. are prime. (These correspond to the Mersenne primes.) In base three: 111, 1111111, 1111111111111, etc. Repunit primes, by definition, are also circular primes. Any repunit in any base having a composite number of digits is necessarily composite. Only repunits (in any base) having a prime number of digits might be prime.
Rather than expanding the repunit out as a giant list of 1s or converting to base 10, it is common to just list the number of 1s in the repunit; effectively the digit count. The base two repunit primes listed above would be represented as: 2, 3, 5, 7, etc. Many of these sequences exist on OEIS, though they aren't specifically listed as "repunit prime digits" sequences. Some bases have very few repunit primes. Bases 4, 8, and likely 16 have only one. Base 9 has none at all. Bases above 16 may have repunit primes as well... but this task is getting large enough already.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Repunit primes step by step in the Wren programming language
Source code in the wren programming language
/* repunit_primes.wren */
import "./gmp" for Mpz
import "./math" for Int
import "./fmt" for Fmt
import "./str" for Str
var limit = 2700
var primes = Int.primeSieve(limit)
for (b in 2..36) {
var rPrimes = []
for (p in primes) {
var s = Mpz.fromStr(Str.repeat("1", p), b)
if (s.probPrime(15) > 0) rPrimes.add(p)
}
Fmt.print("Base $2d: $n", b, rPrimes)
}
You may also check:How to resolve the algorithm Vector step by step in the Modula-2 programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Java programming language
You may also check:How to resolve the algorithm Text processing/2 step by step in the Aime programming language
You may also check:How to resolve the algorithm Ruth-Aaron numbers step by step in the Wren programming language
You may also check:How to resolve the algorithm Roots of unity step by step in the ALGOL 68 programming language