Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1 @@
nth_fib(pow(2;20)) | tostring | [length, .[:10], .[-10:]]

View file

@ -0,0 +1,4 @@
def nth_fib_naive(n):
if (n < 2) then n
else nth_fib_naive(n - 1) + nth_fib_naive(n - 2)
end;

View file

@ -0,0 +1,8 @@
def nth_fib(n):
# input: [f(i-2), f(i-1), countdown]
def fib: (.[0] + .[1]) as $sum
| .[2] as $n
| if ($n <= 0) then $sum
else [ .[1], $sum, $n - 1 ]
| fib end;
[-1, 1, n] | fib;

View file

@ -0,0 +1 @@
(range(0;5), 50) | [., nth_fib(.)]

View file

@ -0,0 +1,6 @@
[0,0]
[1,1]
[2,1]
[3,2]
[4,3]
[50,12586269025]

View file

@ -0,0 +1,7 @@
def fib_binet(n):
(5|sqrt) as $rt
| ((1 + $rt)/2) as $phi
| (($phi | log) * n | exp) as $phin
| (if 0 == (n % 2) then 1 else -1 end) as $sign
| ( ($phin - ($sign / $phin) ) / $rt ) + .5
| floor;

View file

@ -0,0 +1,8 @@
# Generator
def fibonacci(n):
# input: [f(i-2), f(i-1), countdown]
def fib: (.[0] + .[1]) as $sum
| if .[2] == 0 then $sum
else $sum, ([ .[1], $sum, .[2] - 1 ] | fib)
end;
[-1, 1, n] | fib;