fibonacci series what Iam is missing ?
Ian Kelly
ian.g.kelly at gmail.com
Mon Mar 23 16:14:50 EDT 2015
On Mon, Mar 23, 2015 at 12:44 PM, Dave Angel <davea at davea.name> wrote:
> On 03/23/2015 12:16 PM, Chris Angelico wrote:
>> [1] Cue the demonstration of a worse version from someone's student?
>>
>
> I'll give you a worse version. Back in the day I had occasion to write a
> simple program in a language which had no add or subtract. It could only
> increment and decrement indices. So to simulate that:
>
>
> #without using any arithmetic other than increment and decrement
> def fib3(n):
> if n == 0:
> return 0
> elif n == 1:
> return 1
> else:
> a = fib3(n-1)
> n = n-1
> b = fib3(n-1)
> while b > 0: a,b = a+1, b-1
> return a
Function calls? Comparison with numbers other than 0? These are
luxuries, I say! Here's a version that does without:
http://progopedia.com/example/fibonacci/14/
(Note that most of that program is concerned with formatting the
numbers into ASCII for output; the iterative Fibonacci calculation is
just the last part of the loop.)
More information about the Python-list
mailing list