How to resolve the algorithm Pan base non-primes step by step in the Phix programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pan base non-primes step by step in the Phix programming language

Table of Contents

Problem Statement

Primes are prime no matter which base they are expressed in. Some numeric strings are prime in a large number of bases. (Not the same prime, but a prime.) The numeric string "255", while obviously not a prime in base 10, is a prime in bases: among others. There are numeric strings however, that are not a prime in any base. Confining ourselves to 'decimal' numeric strings; the single digit numeric primes are prime in every base where they are a valid number.

The numeric string "2" is a prime in every base except base 2, where it is invalid. The numeric string "3" is a prime in every base except base 2 and 3, where it is invalid. "4" is not a prime in every base except bases 2, 3, and 4 where it is an invalid number (and hence not a prime there either.)

In general, even pan-base non-primes are much more prevalent than odd, though both are fairly common. With the exception of "10", numeric strings that end in 0 are composite in every base where they are valid. Numeric strings where the greatest common divisor of all of the digits is more than 1 are composite in every base. If a "decimal" numeric string N is composite in every base up to base N, it is composite in every base. The digit 1 is an odd-ball case as it is neither prime nor composite. It typically is not included, but due to the ambiguous wording, would not be wrong if it is.

Let's start with the solution: