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

Published on 12 May 2024 09:40 PM

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

Source code in the factor programming language

USING: math.text.utils lists lists.lazy ;

: niven? ( n -- ? ) dup 1 digit-groups sum mod 0 = ;

: first-n-niven ( n -- seq )
    1 lfrom [ niven? ] lfilter ltake list>array ;

: next-niven ( n -- m ) 1 + [ dup niven? ] [ 1 + ] until ;

20 first-n-niven .
1000 next-niven .


  

You may also check:How to resolve the algorithm Caesar cipher step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Empty program step by step in the Scheme programming language
You may also check:How to resolve the algorithm Levenshtein distance step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Loops/While step by step in the V programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the R programming language