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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Harshad or Niven series step by step in the Quackery 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 Quackery programming language

Source code in the quackery programming language

[ number$ $ "0 " swap
  witheach
    [ join $ " + " join ]
  quackery ]               is digitsum  ( n --> n )

[ dup digitsum 
  mod 0 = ]                is isharshad ( n --> b )

say "The first 20 Harshad numbers are: "
 
0 1 
  [ dup isharshad if
     [ dup echo sp dip 1+ ]
    1+
    over 20 = until ]
2drop
cr
cr 
say "The first Harshad number greater than 1000 is: "
 
1000 [ 1+ dup isharshad
       iff echo done
       again ] 
cr

  

You may also check:How to resolve the algorithm Compare length of two strings step by step in the Forth programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the F# programming language
You may also check:How to resolve the algorithm Mertens function step by step in the jq programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the HicEst programming language
You may also check:How to resolve the algorithm Address of a variable step by step in the X86 Assembly programming language