Inverse Colombian Function Let's define a sequence: The n digit summing sequence (n-DSS) is a sequence that starts with n. If the last number was k, then the next number is k + digit-sum(k). Here are the first few n-DSS:

1-DSS: 1, 2, 4, 8, 16, 23, 28, 38, 49, 62, 70...
2-DSS: 2, 4, 8, 16, 23, 28, 38, 49, 62, 70, 77...
3-DSS: 3, 6, 12, 15, 21, 24, 30, 33, 39, 51, 57...
4-DSS: 4, 8, 16, 23, 28, 38, 49, 62, 70, 77, 91...
5-DSS: 5, 10, 11, 13, 17, 25, 32, 37, 47, 58, 71...
6-DSS: 6, 12, 15, 21, 24, 30, 33, 39, 51, 57, 69...
7-DSS: 7, 14, 19, 29, 40, 44, 52, 59, 73, 83, 94...
8-DSS: 8, 16, 23, 28, 38, 49, 62, 70, 77, 91, 101...
9-DSS: 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99...


For 1, this is A004207, although the first few digits are different due to a slightly different definition. For 3, it's A016052; for 9, A016096.

Today's challenge is to find the lowest n digit sum sequence that a given number appears in. This is called the "Inverse Colombian Function", and is A036233. The first twenty terms, starting with 1 are:

1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 5, 3, 5, 7, 3, 1, 5, 9, 7, 20


Some other good test cases:

117: 9
1008: 918


You only have to handle integers greater than 0, and you can take input and output in any standard format. As usual, this is code-golf, so shortest answer in each language wins.
Haskell, 104 64 63 bytes

(-26 thanks to H.PWiz, additional -14 thanks to Sriotchilism O'Zaic, additional -1 thanks to cole)

This is a function.



f x=[y|y&lt;-[1..],x==until(&gt;=x)(foldr((+).read.pure)&lt;*&gt;show)y]!!0


Try it online!



Explanation:

(foldr((+).read.pure)&lt;*&gt;show)


Sequence of composited functions that returns y+digital sum of y. Converts to string first, then does some monad gymnastics to get the sum of the characters and the original number (thanks to Cole).

The &lt;*&gt; operator in this context has type and definition

(&lt;*&gt;) :: (a -&gt; b -&gt; c) -&gt; (a -&gt; b) -&gt; c
f &lt;*&gt; g = \x -&gt; f x (g x)


so we can write the above as

\x -&gt; foldr ((+) . read . pure) x (show x)


This read . pure converts a Char into a number, so (+) . read . pure :: Char -&gt; Int -&gt; Int adds a digit to an accumulated value. This value is initialized to the given number in the fold.

until (&gt;=x) {- digital sum function -} y


until repeatedly applies a function to its result (in this case, the y+digital sum y) until it meets a requirement specified by a function in the first argument. This gives the smallest y-DSS element that's greater or equal to x.

[y | y&lt;-[1..]; x == {- smallest y-DSS element &gt;= x -} ]


Infinite lazy list of y's such that the smallest y-DSS element >= x is actually x. Uses Haskell's list comprehension notation (which I'd also totally forgotten about, thank y'all).

f x = {- aforementioned list -} !! 0


First element of that list, which is the smallest y that satisfies the requirement of the challenge.