How to resolve the algorithm Home primes step by step in the Sidef programming language
How to resolve the algorithm Home primes step by step in the Sidef programming language
Table of Contents
Problem Statement
In number theory, the home prime HP(n) of an integer n greater than 1 is the prime number obtained by repeatedly factoring the increasing concatenation of prime factors including repetitions. The traditional notation has the prefix "HP" and a postfix count of the number of iterations until the home prime is found (if the count is greater than 0), for instance HP4(2) === HP22(1) === 211 is the same as saying the home prime of 4 needs 2 iterations and is the same as the home prime of 22 which needs 1 iteration, and (both) resolve to 211, a prime. Prime numbers are their own home prime; So: If the integer obtained by concatenating increasing prime factors is not prime, iterate until you reach a prime number; the home prime.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Home primes step by step in the Sidef programming language
Source code in the sidef programming language
for n in (2..20, 65) {
var steps = []
var orig = n
for (var f = n.factor; true; f = n.factor) {
steps << f
n = Num(f.join)
break if n.is_prime
}
say ("HP(#{orig}) = ", steps.map { .join('_') }.join(' -> '))
}
You may also check:How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the 11l programming language
You may also check:How to resolve the algorithm Stack step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Canny edge detector step by step in the PHP programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Topswops step by step in the XPL0 programming language