5 kyu

Right Truncatable Harshad numbers

57 of 90anter69

Description:

This kata is inspired by Project Euler Problem #387

Description

A Harshad number (or Niven number) is a number that is divisible by the sum of its digits. A right truncatable Harshad number is any Harshad number that, when recursively right-truncated, results in a Harshad number at each truncation. By definition, 1-digit numbers are not right truncatable Harshad numbers.

For example 201 (which is a Harshad number) yields 20, then 2 when right-truncated, which are all Harshad numbers. Thus 201 is a right truncatable Harshad number.

Your task

Given a range of numbers (a..b, both included), return the list of right truncatable Harshad numbers in this range.

Note: there are 500 random tests, with 0 <= a <= b <= 1016

Examples

0, 20        -->  [10, 12, 18, 20]
30, 100      -->  [30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100]
90, 200      -->  [90, 100, 102, 108, 120, 126, 180, 200]
200, 210     -->  [200, 201, 204, 207, 209, 210]
1000, 2000   -->  [1000, 1002, 1008, 1020, 1026, 1080, 1088, 1200, 1204, 1206, 1260, 1800, 2000]
2200, 2300   -->  []
9000002182976, 9000195371842  -->  [9000004000000, 9000004000008]

My other katas

If you enjoyed this kata then please try my other katas! :-)

Translations are welcome!

Mathematics
Number Theory
Algorithms

Stats:

CreatedMar 8, 2019
PublishedMar 8, 2019
Warriors Trained779
Total Skips40
Total Code Submissions829
Total Times Completed90
Python Completions57
Ruby Completions15
Haskell Completions10
JavaScript Completions23
Elixir Completions4
Total Stars33
% of votes with a positive feedback rating89% of 40
Total "Very Satisfied" Votes32
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • anter69 Avatar
  • docgunthrop Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
Ad