How to resolve the algorithm Attractive numbers step by step in the Insitux programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Attractive numbers step by step in the Insitux programming language
Table of Contents
Problem Statement
A number is an attractive number if the number of its prime factors (whether distinct or not) is also prime.
The number 20, whose prime decomposition is 2 × 2 × 5, is an attractive number because the number of its prime factors (3) is also prime.
Show sequence items up to 120.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Attractive numbers step by step in the Insitux programming language
Source code in the insitux programming language
(function primes n
(let find-range (range 2 (inc n))
check-nums (range 2 (-> n ceil sqrt inc))
skip-each-after #(skip-each % (skip %1 %2))
muls (xmap #(drop 0 (skip-each-after (dec %1) % find-range)) check-nums))
(remove (flatten muls) find-range))
(function distinct-factor n
(filter @(div? n) (primes n)))
(function factor n
(map (fn t (find (div? n) (map @(** t) (range (round (sqrt n)) 0)))) (distinct-factor n)))
(function decomposed-factors n
(map (fn dist t (repeat dist (/ (logn t) (logn dist)))) (distinct-factor n) (factor n)))
(var prime? @((primes %)))
(var attract-num? (comp decomposed-factors flatten len prime?))
(filter attract-num? (range 121))
You may also check:How to resolve the algorithm Percentage difference between images step by step in the Raku programming language
You may also check:How to resolve the algorithm Text processing/2 step by step in the Go programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Sutherland-Hodgman polygon clipping step by step in the Scheme programming language