Random Variable
Lifer
I took me forever to write a simple program using Maple that would sum the first n terms of the Fibonacci sequence. My programming skills suck. 😱 Would anyone have done it differently?
EDIT: I apologzie for the lack of spacing but FuseTalk sucks at spacing.
Fibon:=proc(n)
local s, F1, F2, F3, k;
if n=1 then
print(0);
elif n=2 then
print(1);
else
s:=1;
F1:=0;
F2:=1;
for k from 3 to n do
s:=s+F1+F2;
F3:=F1+F2
F1:=F2;
F2:=F3;
end do;
print(s);
end if;
end proc;
EDIT: I apologzie for the lack of spacing but FuseTalk sucks at spacing.
Fibon:=proc(n)
local s, F1, F2, F3, k;
if n=1 then
print(0);
elif n=2 then
print(1);
else
s:=1;
F1:=0;
F2:=1;
for k from 3 to n do
s:=s+F1+F2;
F3:=F1+F2
F1:=F2;
F2:=F3;
end do;
print(s);
end if;
end proc;