How to resolve the algorithm Anti-primes step by step in the AWK programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anti-primes step by step in the AWK programming language

Table of Contents

Problem Statement

The anti-primes (or highly composite numbers, sequence A002182 in the OEIS) are the natural numbers with more factors than any smaller than itself.

Generate and show here, the first twenty anti-primes.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Anti-primes step by step in the AWK programming language

Source code in the awk programming language

# syntax: GAWK -f ANTI-PRIMES.AWK
BEGIN {
    print("The first 20 anti-primes are:")
    while (count < 20) {
      d = count_divisors(++n)
      if (d > max_divisors) {
        printf("%d ",n)
        max_divisors = d
        count++
      }
    }
    printf("\n")
    exit(0)
}
function count_divisors(n,  count,i) {
    if (n < 2) {
      return(1)
    }
    count = 2
    for (i=2; i<=n/2; i++) {
      if (n % i == 0) {
        count++
      }
    }
    return(count)
}


  

You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the C programming language
You may also check:How to resolve the algorithm Echo server step by step in the Raku programming language
You may also check:How to resolve the algorithm Aliquot sequence classifications step by step in the VBA programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the BASIC programming language
You may also check:How to resolve the algorithm Here document step by step in the XPL0 programming language