How to resolve the algorithm Attractive numbers step by step in the jq programming language

Published on 12 May 2024 09:40 PM
#Jq

How to resolve the algorithm Attractive numbers step by step in the jq 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 jq programming language

Source code in the jq programming language

def count(s): reduce s as $x (null; .+1);

def is_attractive:
  count(prime_factors) | is_prime;

def printattractive($m; $n):
  "The attractive numbers from \($m) to \($n) are:\n",
  [range($m; $n+1) | select(is_attractive)];
 
printattractive(1; 120)

  

You may also check:How to resolve the algorithm System time step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Phrase reversals step by step in the AWK programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Odin programming language
You may also check:How to resolve the algorithm Stack step by step in the PicoLisp programming language