amitabha@rochester.UUCP (Amitabha Mukhopadhyay) (02/13/85)
In article <545@decwrl.UUCP> osman@sprite.DEC (Eric Osman) writes: >Subject: solve 1 + 11 + 111 . . . + n 1's > >Let n1 be the last number in the sequence, i.e. n 1's. > >The answer for a given n is 1 + 11 + 111 + . . . + n1 > > a(n) = (10*n1 - n) / 9 > >The way I solved it was to observe that the sum is a portion of an infinite >converging geometric series........ In what may be a simpler process, let s be the sum desired. Then resolving into powers of 10, s = 10**(n-1) + 2*10**(n-2) + .. + m*10**(n-m) + .. + n*1 Dividing s by 10, s/10 = 10**(n-2) + .. + (m-1)*10**(n-m) +..+ (n-1) + n/10 (s-s/10) is clearly a geometric series in 10 with a residue of -n/10. 0.9*s = 10**(n-1) + 10**(n-2) + .. + 10**(n-m) + .. + 1 - n/10 = (10**n - 1)/9 - n/10 or, s = (10**n - 1)/8.1 - n/9 Which can be simplified to Eric's format if we write 10**n - 1 = n1 * 9, where n1 is n 1's (111111.. n times). s = n1 * 10/9 - n/9 = (n1*10 - n)/9 >At this point, I smiled and went back to more important(?) hacking. ------------------------------------------------------------------------- Amitabha Mukerjee <amitabha@rochester.arpa> Here's to you and here's to me And I hope we never disagree, But if we do then to heck with YOU, And here's to ME! -------------------------------------------------------------------------