This question is founded in Project Euler #34. I originally solved the problem years ago but now I'm moving all the problems over to a new language. As I revisit this problem, I already know the answer but I don't know when to stop looking for the answer.
The task itself, minus lead up and notes, is
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
The task of summing factorials is trivial. What isn't obvious to me is how do I know when I've found them all? I don't want to give away the answer to the question but here's what I know:
I know that there are only 2 of these numbers: 145 as mentioned in the questions example and 40585.
When do I know to stop looking? How do I know that the biggest of these numbers is THE biggest and there won't be any more?
As Rubberchicken pointed out: the maximum value the sum of the factorials of an $n-$digit number is $9!(n)$ While the smallest value a number of $n$ digits can have is $10^{n-1}$.
So you only have to check for numbers which satisfy $9!(n)>10^n\iff362880n>10^n\iff n<6.6$
So you only have to check up to $999999$