```"Rick DeNatale" <rick.denatale / gmail.com> writes:

> On 9/6/06, Daniel Martin <martin / snowplow.org> wrote:
>> I strongly doubt that this method is the most
>> efficient way to get to a 9-step number; as a trivial adjustment, the
>> number
>>
>>   ("1" * 24 + "9" * 975).to_i
>>
>> is also a 9-step number.
>
> I think you lost me on that step.

Sorry; I didn't show all my work.

irb(main):037:0> 78999.divmod(81)
=> [975, 24]
irb(main):038:0> 81 * 975 + 24
=> 78999

>>However, if 78999 is the smallest 8-step
>> happy number, the smallest 9-step happy number must have at least
>> (78999/81.0).ceil digits.  Small wonder that you didn't find one...
>
> Efficient or not, it would seem that generating large happy numbers by
> construction beats the hell out of trying to find them.

Probably.  I'm reasonably certain that it can be shown that the
smallest 9-step number feeds into the smallest 8-step number, but I'm
not certain about that.  I'm also a bit unclear on how to generate
them by construction in an efficient manner to make sure I get them
all. (consider that adding a 0 anywhere in a n-step happy number makes
another n-step happy number; this adds wrinkles I don't want to think

However, if I had hit on the idea of generating happy numbers by
construction earlier in the quiz, I might have spent Saturday working
that out.  Oh well.

Incidentally, I'm pretty sure now that the smallest 9-step number is:

("3788" + "9" * 973).to_i

with 977 digits.  Note that:

irb(main):020:0> ("3788" + "9"*973).split(//).inject(0){|s,x|s+(x.to_i**2)}
=> 78999

--
s=%q(  Daniel Martin -- martin / snowplow.org
puts "s=%q(#{s})",s.map{|i|i}[1]       )
puts "s=%q(#{s})",s.map{|i|i}[1]

```