How to resolve the algorithm Harshad or Niven series step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Harshad or Niven series step by step in the PicoLisp programming language

Table of Contents

Problem Statement

The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits. For example,   42   is a Harshad number as   42   is divisible by   (4 + 2)   without remainder. Assume that the series is defined as the numbers in increasing order.

The task is to create a function/method/procedure to generate successive members of the Harshad sequence. Use it to:

Show your output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Harshad or Niven series step by step in the PicoLisp programming language

Source code in the picolisp programming language

#if niven number, return it.
(de niven (N)
   (if (=0 (% N (apply + (getN N)))) N) )

#function which creates a list of numbers from input
(de getN (N)
   (mapcar format (chop N)) )

#This function generates niven number list
(de nivGen (R N)
   (extract niven (range R N)) )

#print 1st 20 niven numbers and 1st niven number greater than 1000
(printsp ~(list ~(head 20
                    (nivGen 1 1000) ) (max ~(nivGen 1001 1010)) ) )

  

You may also check:How to resolve the algorithm P-value correction step by step in the Nim programming language
You may also check:How to resolve the algorithm Set of real numbers step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Untouchable numbers step by step in the J programming language
You may also check:How to resolve the algorithm User input/Text step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the PowerShell programming language