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


 
note
	description : "project application root class"
	date        : "$October 10, 2014$"
	revision    : "$Revision$"
 
class
	NIVEN_SERIES
 
create
	make
 
feature
	make
		local
			number : INTEGER
			count : INTEGER
			last : BOOLEAN
		do
			number := 1
 
			from
				number := 1
				last := false
 
			until
				last = true
 
			loop
 
				if
					(number \\ sum_of_digits(number) = 0)
				then
					count := count + 1
 
					if
						(count <= 20 )
					then
						print("%N")
						print(number)
					end
 
					if
						(number > 1000)
					then
						print("%N")
						print(number)
						last := true
					end
				end
 
				 number := number + 1
			end
		end
 
	sum_of_digits(no:INTEGER):INTEGER
 
		local
			sum : INTEGER
			num : INTEGER
		do
			sum := 0
 
			from
				num := no
 
			until
				num = 0
 
			loop
				sum := sum + num \\ 10
				num := num // 10
			end
 
			Result := sum
		end
end
 
 