Fibonacci sequence: Difference between revisions

m
PL/0: The last line of a "begin" compound statement must not be terminated with a semicolon. Unusual but true!
No edit summary
m (PL/0: The last line of a "begin" compound statement must not be terminated with a semicolon. Unusual but true!)
(5 intermediate revisions by 5 users not shown)
Line 3,018:
150 END
</syntaxhighlight>
 
==={{header|Tiny Craft Basic}}===
<syntaxhighlight lang="basic">10 cls
 
20 let a = 1
30 let b = 1
 
40 print "Fibonacci Sequence"
 
50 rem loop
 
60 let s = a + b
70 let a = b
80 let b = s
90 let i = i + 1
 
100 print s
 
120 if i < 20 then 50
 
130 shell "pause"
140 end</syntaxhighlight>
 
==={{header|True BASIC}}===
Line 3,309 ⟶ 3,287:
 
==={{header|Yabasic}}===
====Iterative====
<syntaxhighlight lang="yabasicvbnet">sub fibonaccifibonacciI (n)
local n1, n2, k, sum
 
n1 = 0
n2 = 1
Line 3,317 ⟶ 3,298:
n2 = sum
next k
if n < 01 then
return n1 * ((-1) ^ ((-n) + 1))
else
return n1
end if
140 end sub</syntaxhighlight>
 
====Recursive====
Only positive numbers
<syntaxhighlight lang="vbnet">sub fibonacciR(n)
120 if in <= 201 then 50
return n
else
return fibonacciR(n-1) + fibonacciR(n-2)
end if
end sub</syntaxhighlight>
 
====Analytic====
Only positive numbers
<syntaxhighlight lang="vbnet">sub fibonacciA (n)
return int(0.5 + (((sqrt(5) + 1) / 2) ^ n) / sqrt(5))
end sub</syntaxhighlight>
 
====Binet's formula====
Fibonacci sequence using the Binet formula
<syntaxhighlight lang="vbnet">sub fibonacciB(n)
local sq5, phi1, phi2, dn1, dn2, k
 
sq5 = sqrt(5)
phi1 = (1 + sq5) / 2
phi2 = (1 - sq5) / 2
dn1 = phi1: dn2 = phi2
for k = 0 to n
dn1 = dn1 * phi1
dn2 = dn2 * phi2
print int(((dn1 - dn2) / sq5) + .5);
next k
end sub</syntaxhighlight>
 
Line 8,318 ⟶ 8,331:
 
=={{header|langur}}==
<syntaxhighlight lang="langur">val .fibonacci = ffn(.x) if(.x < 2: .x ; self(.x - 1) + self(.x - 2))
 
writeln map .fibonacci, series 2..20</syntaxhighlight>
Line 10,243 ⟶ 10,256:
Custom Iterator:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
C:\Users\dersoy\Documents\GitHub\onyx\fib>
</pre>
 
Line 11,208 ⟶ 11,220:
i := i + 1
end;
! b;
end.
</syntaxhighlight>
Line 14,391 ⟶ 14,403:
fibionacci 46=1836311903
</pre>
 
==={{header|Tiny Craft BasicUiua}}===
{{works with|Uiua|0.10.0-dev.1}}
Simple recursive example with memoisation.
<syntaxhighlight lang="basicUiua">10 cls
F ← |1 memo⟨+⊃(F-1)(F-2)|∘⟩<2.
F ⇡20
</syntaxhighlight>
 
=={{header|UNIX Shell}}==