A number n is a self number if there is no number g such that g + the sum of g's digits = n. So 18 is not a self number because 9+9=18, 43 is not a self number because 35+5+3=43.


The task is:

 Display the first 50 self numbers;
 I believe that the 100000000th self number is 1022727208. You should either confirm or dispute my conjecture.

224036583-1 is a Mersenne prime, claimed to also be a self number. Extra credit to anyone proving it.


See also
 
OEIS: A003052 - Self numbers or Colombian numbers
Wikipedia: Self numbers
func is_self_number(n) {
 
    if (n < 30) {
        return (((n < 10) && (n.is_odd)) || (n == 20))
    }
 
    var qd = (1 + n.ilog10)
    var r  = (1 + (n-1)%9)
    var h  = (r + 9*(r%2))/2
    var ld = 10
 
    while (h + 9*qd >= n%ld) {
        ld *= 10
    }
 
    var vs = idiv(n, ld).sumdigits
    n %= ld
 
    0..qd -> none { |i|
        vs + sumdigits(n - h - 9*i) == (h + 9*i)
    }
}
 
say is_self_number.first(50).join(' ')