Fibonacci sequence: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Matrix exponentiation alternative) |
(+Oz) |
||
Line 326: | Line 326: | ||
) |
) |
||
=={{header|Oz}}== |
|||
fun{FibI N} %% Iterative using Cell |
|||
Temp = {NewCell 0} |
|||
A = {NewCell 0} |
|||
B = {NewCell 1} |
|||
in |
|||
for I in 1..N do |
|||
Temp := @A + @B |
|||
A := @B |
|||
B := @Temp |
|||
end |
|||
@A %% return result |
|||
end |
|||
fun{Fibi N} %% Iterative(or Recursive?) by arguments swapping |
|||
fun{FibIter N A B} |
|||
if N == 0 then B |
|||
else {FibIter N-1 A+B A} end |
|||
end |
|||
in |
|||
if N < 2 then N |
|||
else {FibIter N 1 0} end |
|||
end |
|||
fun{FibR N} %% Simple Recursive |
|||
if N < 2 then N |
|||
else {FibR N-1} + {FibR N-2} end |
|||
end |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<perl>#!/usr/bin/perl -w |
<perl>#!/usr/bin/perl -w |