How to resolve the algorithm Harshad or Niven series step by step in the EchoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Harshad or Niven series step by step in the EchoLisp 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 EchoLisp programming language
Source code in the echolisp programming language
(define (harsh? n)
(zero? (modulo n
(apply + (map string->number (string->list (number->string n)))))))
(harsh? 42)
→ #t
(define H (stream-filter harsh? (in-naturals 1)))
(take H 20)
→ (1 2 3 4 5 6 7 8 9 10 12 18 20 21 24 27 30 36 40 42)
(for ((n H)) #:break (> n 1000) => n)
→ 1002
You may also check:How to resolve the algorithm Higher-order functions step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Taxicab numbers step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Find common directory path step by step in the Aime programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Wren programming language
You may also check:How to resolve the algorithm Map range step by step in the R programming language