mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
28 lines
598 B
Plaintext
Executable File
28 lines
598 B
Plaintext
Executable File
fib := n -> {
|
|
// we start with these two values
|
|
v := (0, 1)
|
|
{() -> {
|
|
// subtract 1 from n
|
|
&n = (n, -1).sum
|
|
// extract the latest values
|
|
(l, r) := v
|
|
// if n is still positive...
|
|
if (n.signum, 1).eq {
|
|
// ...advance the fib. sequence
|
|
&v = (r, v.sum)
|
|
// and don't break from the loop
|
|
()
|
|
} else {
|
|
// n is zero or negative (happens the n-th time this loop runs),
|
|
// so we break with the latest value
|
|
(r)
|
|
}
|
|
}}.loop
|
|
}
|
|
|
|
((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 100), i -> {
|
|
i.print
|
|
": ".print
|
|
i.fib.println
|
|
}).for_each
|