4
Write a program that print sum of as many Fibonacci numbers as possible. There is a limit in that your program should not run more than 10s on 2GHz single core PC. (equivalents are acceptable, for instance you have twice as many time on 1GHz PC). Memory consumption is not limited, but provide details, if you exceed normal values.
Your program has to work with different input values. Output can be calculated modulo 10^i, but i has to be at least 9 digits. Other types of results are also welcome as long as they are presented with 9 digits and are not trivially calculated.
Post source, language input value and result.
Define "trivially calculated". Are you saying that we can apply mathematical identities to optimise it up to some cutoff point? If so, what precisely is the cutoff point? – Peter Taylor – 2011-04-14T18:44:01.490
3
@ralu Instead of giving a PC specification, you can also say print the maximum sum of fibonacci numbers before it times out on http://www.ideone.com/ . That way everyone will have a common ground. The time limit there is 5 secs.
– fR0DDY – 2011-04-15T03:23:57.867did not knew. That looks fair – ralu – 2011-04-15T07:27:57.627
What kind of input values are you talking about? – user unknown – 2011-04-16T01:40:28.503
The question is still unclear to me. For arbitrary input, each machine will reach a limit in 10s, so does 'as many as possible' mean, that the program shall interrupt, and print the sum so far? If you have a timelimit, the program could be interrupted from outside, and show, what it reached. – user unknown – 2011-04-18T12:09:00.293
Again a question: How do you decide who has won from 9 digits? – user unknown – 2011-04-18T13:08:37.677
@user, to the second question, I interpreted "input value" as meaning that your program should print the number of terms added. I.e. you need to output
n
andF(n+2)-1
. – Peter Taylor – 2011-04-19T16:16:39.727And what is n? Do you start (0, 1, ...) or (1, 1, ...)? And count index from 0 or 1? So f(8)=13? – user unknown – 2011-04-19T18:49:13.407
@Peter: So most answers are wrong, since they output a random something - not related to the input. The question should be rephrased: "Print the sum of all fibonacci-number up to i [% 10^(9+n)] (fib(0)=0, fib(1)=1, ...). Make your program as fast as possible. Time-measurement will be made from outside. After 10s on an (REFERENCE-PC-SPEC), it will be interrupted if not ready. Winner is, who reaches the highest, correct value in that time, and only correct results along the way." – user unknown – 2011-04-20T03:28:21.013
1@user,
n
is the number of Fibonacci numbers counted. The question doesn't specify whether 1,1 is F(0),F(1) or F(1),F(2), so I chose the one which gives the nicest properties (the second). Keith has interpreted the question slightly differently to me - he takes actual inputi
and outputsF(ki + 2) - 1
; I think his answer and mine are both correct. But it's pointless getting fussed about it because it's a bad question: I don't think @ralu realised that the sum of Fibonacci numbers is so easily reduced to computing one Fibonacci number, or that the period modN
is so short. – Peter Taylor – 2011-04-20T06:16:22.447