3
\$\begingroup\$

Task

Write a function or program that takes n as a parameter and prints the first n self-divisors.

Definition of Self-divisor

A positive integer is called a “self-divisor” if every decimal digit of the number is a divisor of the number, that is, the number is evenly divisible by each and every one of its digits.

Example

For example, the number 128 is a self-divisor because it is evenly divisible by 1, 2, and 8. However, 26 is not a self-divisor because it is not evenly divisible by the digit 6. Note that 0 is not considered to be a divisor of any number, so any number containing a 0 digit is NOT a self-divisor. There are infinitely many self-divisors.

Scoring

This is code-golf, so the shortest answer in bytes wins

\$\endgroup\$
  • \$\begingroup\$ This seems really familiar, I'm pretty sure I've golf this challenge here before, or at least one that determines if a number is a self-divisor, but I'm not finding it now. \$\endgroup\$ – xnor Apr 28 at 3:22
  • \$\begingroup\$ Are we allowed to take the index - 1, as per sequence defaults? (Or simply output the whole sequence) \$\endgroup\$ – user92069 Apr 28 at 3:24
  • \$\begingroup\$ @xnor I believe that is this question. Duplicate? \$\endgroup\$ – dingledooper Apr 28 at 3:25
  • \$\begingroup\$ @dingledooper Thanks, too bad SE search doesn't show that on the first page of "divide digit". \$\endgroup\$ – xnor Apr 28 at 3:28
  • \$\begingroup\$ I think this is a duplicate because the additional part of "output the first n" isn't enough to make it different. People should feel free to reopen if they feel otherwise. I guess there's an argument that the other question is too old and has weird rules? \$\endgroup\$ – xnor Apr 28 at 3:30
0
\$\begingroup\$

05AB1E, 16 bytes

05AB1E probably has some sort of slice, but I failed to find it.

∞ʒDSÖß}ʒ0å_}ηs<è

Try it online!

Explanation

∞                [1, 2, 3, ...]
 ʒ               Filter all that satisfies:
  DS                 its DigitS
    Ö                is divisible
     ß}              ßy the original number.
       ʒ         Filter out ^ that satisfies:
        0å_}         0 is å digit of the output.
            ηs<è Trunctuatè by the input.
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think this is missing 1 in the output \$\endgroup\$ – math junkie Apr 28 at 3:19
  • \$\begingroup\$ @mathjunkie Probably fixed. \$\endgroup\$ – user92069 Apr 28 at 3:22
  • \$\begingroup\$ 8 bytes in the legacy version of 05AB1E: µNDSÖPD– (The second and fourth bullet-points of this 05AB1E tip are relevant.) PS: £ is what you were probably looking for? \$\endgroup\$ – Kevin Cruijssen Apr 28 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.