November 8th, 2012, 03:56 PM
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.
I tried a few ways around but it always takes my computer from 2 to 3 minutes to complete the calculation...
November 8th, 2012, 04:32 PM
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.
so you start with the sum
You next need
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.
[/code] are essential for python code and Makefiles!
November 9th, 2012, 09:04 AM
Originally Posted by b49P23TIvg
HAHAHA! what was I thinking I really thought this would turn out to be way harder, I guess the time limitation thing brought me to think way too far methods.
Dear sir, you saved me from "me". Thank you.