What is this called in Mathematics

92 Views Asked by At

I am not a Mathematician. I am a programmer. While working on a mock interview question I noticed something I found interesting.

The problem was to return the smallest number (N), whose sum of its digits totaled another supplied/known number (X).(There was other stuff leading up to that too)

  • given 12, the answer is 39
  • given 62, the answer is 8999999
  • given 156, the answer is 399999999999999999

I realised dividing any number (X) by 9, and placing the first digit after the decimal at the start, followed by Y number of 9's (Where Y is how many times 9 goes into the X), would give the smallest answer as required.

44/9=4.8888 return 89999

My colleagues just did a while loop until the got a number. Which I think is yucky.

I know I'm not some math genius. Can someone tell me what this is called? I have no idea. Is it just basic division :)