Thread: Python problem; big number handling!

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
32
Rep Power
3

Python problem; big number handling!

This is the given problem.
Write a function in Python that receives as input 5^100000. the program must calculate and return the sum of the 60000 maximal consecutive digits. Sample: If input is 123456789, the output must be 35 (5+6+7+8+9).

Note: the program must be as efficient as possible. Run time: a few seconds to one minute maximum on a lower end computer.

The program must output 269304 for checking purposes.

Help anyone?
I tried a few ways around but it always takes my computer from 2 to 3 minutes to complete the calculation...
2. Few seconds is way too long for this calculation.

suppose you have a number with digits (and these are integers 0 through 9)
a b c d e f
you need to find the maximal sum of 3 consecutive digits.
a+b+c
You next need
b+c+d
do you have to add b, c, and d?
No! You can subtract `a' and add `d'. And that's a saving for sequences longer than 3.

Oh dear too many clues.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
32
Rep Power
3
Originally Posted by b49P23TIvg
Few seconds is way too long for this calculation.

suppose you have a number with digits (and these are integers 0 through 9)
a b c d e f
you need to find the maximal sum of 3 consecutive digits.