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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anti-primes step by step in the Common Lisp 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 Common Lisp programming language

Source code in the common programming language

(defun factors (n &aux (lows '()) (highs '()))
    (do ((limit (1+ (isqrt n))) (factor 1 (1+ factor)))
        ((= factor limit)
            (when (= n (* limit limit))
                (push limit highs))
            (remove-duplicates (nreconc lows highs)))
        (multiple-value-bind (quotient remainder) (floor n factor)
            (when (zerop remainder)
                (push factor lows)
                (push quotient highs)))))

(defun anti-prime ()
    (format t "The first 20 anti-primes are :~%")
    (do ((dmax 0) (c 0) (i 0 (1+ i)))
        ((= c 20))
        (setf facts (list-length (factors i)))
        (when (< dmax facts)
            (format t "~d " i)
            (setq dmax facts)
            (incf c))))


  

You may also check:How to resolve the algorithm Exceptions step by step in the Nim programming language
You may also check:How to resolve the algorithm Multiple regression step by step in the jq programming language
You may also check:How to resolve the algorithm Roots of a quadratic function step by step in the ERRE programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Rate counter step by step in the Ring programming language