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.



Task

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

Use it to:

   list the first 20 members of the sequence,   and
   list the first Harshad number greater than 1000.


Show your output here.



Related task
   Increasing gaps between consecutive Niven numbers


See also
    OEIS: A005349


#APPTYPE CONSOLE
 
CLASS harshad
    PRIVATE:
    memo[]
 
    SUB INITIALIZE()
        DIM i = 1, c
        DO
            IF isNiven(i) THEN
                c = c + 1
                memo[c] = i
            END IF
            i = i + 1
            IF c = 20 THEN EXIT DO
        LOOP
        memo[] = "..."
        i = 1000
        WHILE NOT isNiven(INCR(i)): WEND
        memo[] = i
    END SUB
 
    FUNCTION isNiven(n)
        RETURN NOT (n MOD sumdigits(n))
    END FUNCTION
 
    FUNCTION sumdigits(n)
        DIM num = n, m, sum
        WHILE num
            sum = sum + num MOD 10
            num = num \ 10
        WEND
        RETURN sum
    END FUNCTION
 
    PUBLIC:
    METHOD Yield()
        FOREACH DIM e IN memo
            PRINT e, " ";
        NEXT
    END METHOD
END CLASS
 
DIM niven AS NEW harshad
niven.Yield()
 
PAUSE
 