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
 
defmodule SelfNums do
 
  def digAndSum(number) when is_number(number) do
    Integer.digits(number) |>
    Enum.reduce( 0, fn(num, acc) -> num + acc end ) |>
    (fn(x) -> x + number end).()
  end
 
  def selfFilter(list, firstNth) do
    numRange = Enum.to_list 1..firstNth
    numRange -- list 
  end
 
end
 
defmodule SelfTest do
 
  import SelfNums
  stop = 1000
  Enum.to_list 1..stop |>
  Enum.map(&digAndSum/1) |>
  SelfNums.selfFilter(stop) |>
  Enum.take(50) |>
  IO.inspect
 
end
 