Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,6 @@
(let fibo (fun (n)
(if (< n 2)
n
(+ (fibo (- n 1)) (fibo (- n 2))))))
(assert (= 6765 (fibo 20)) "(fibo 20) == 6765")

View file

@ -0,0 +1,12 @@
(let fibo (fun (n) {
(mut i 0)
(mut a 0)
(mut b 1)
(while (< i n) {
(let c (+ a b))
(set a b)
(set b c)
(set i (+ 1 i)) })
a }))
(assert (= 6765 (fibo 20)) "(fibo 20) == 6765")

View file

@ -0,0 +1,11 @@
create or replace function fib_to(n) as table (
with recursive fib(e,f) as (
select 1, 1
union all
select e+f,e from fib
where e <= n)
select f from fib
order by f
);
from fib_to(55);

View file

@ -0,0 +1,2 @@
select round ( power( ( 1 + sqrt( 5 ) ) / 2, level ) / sqrt( 5 ) ) fib
from range(1,11) t(level);

View file

@ -0,0 +1 @@
SELECT 0::UHUGEINT, 1::UHUGEINT

View file

@ -0,0 +1,16 @@
# Warning: the following program has been naively adapted from the PostgresQL but
# should be further modified to ensure correctness, e.g. by adding a counter
CREATE or replace FUNCTION fib(n) AS (
WITH RECURSIVE fibonacci(current, previous) AS (
SELECT 0::UHUGEINT, 1::UHUGEINT
-- another possibility: SELECT 0::FLOAT, 1::FLOAT
UNION ALL
SELECT previous + current, current FROM fibonacci
)
SELECT current FROM fibonacci
LIMIT 1 OFFSET n
);
# Example
select fib(100);

View file

@ -24,6 +24,6 @@ public program()
{
for(int i := 0; i <= 10; i+=1)
{
console.printLine(fibu(i))
Console.printLine(fibu(i))
}
}

View file

@ -1,34 +1,40 @@
import extensions;
public FibonacciGenerator
singleton FibonacciEnumerable : Enumerable
{
yieldable next()
{
Enumerator enumerator()
= FibonacciEnumerable.infinitEnumerator();
yield Enumerator infinitEnumerator()
{
long n_2 := 1l;
long n_1 := 1l;
$yield n_2;
$yield n_1;
:yield n_2;
:yield n_1;
while(true)
{
long n := n_2 + n_1;
$yield n;
:yield n;
n_2 := n_1;
n_1 := n
}
}
}
}
public program()
{
auto e := new FibonacciGenerator();
auto e := FibonacciEnumerable.enumerator();
for(int i := 0; i < 10; i += 1) {
console.printLine(e.next())
if(!e.next())
InvalidOperationException.raise();
for(int i := 0; i < 10 && e.next(); i += 1) {
Console.printLine(*e)
};
console.readChar()
Console.readChar()
}

View file

@ -0,0 +1,11 @@
function fib(n)
local a, b = 0, 1
for _ = 1,n do
a,b = b,a+b
end
return a
end
for i = 0,10 do
print(fib(i))
end

View file

@ -0,0 +1,6 @@
#lang rhombus/static
fun fib:
| fib(0): 1
| fib(1): 1
| fib(n): fib(n-2) + fib(n-1)

View file

@ -0,0 +1,14 @@
#lang rhombus/static
def cache = MutableMap()
fun fib:
| fib(0): 1
| fib(1): 1
| fib(n):
guard n !in cache | cache[n]
let result = fib(n-2) + fib(n-1)
cache[n] := result
result
fib(100) // 573147844013817084101

View file

@ -0,0 +1,8 @@
\ Fibonacci numbers (iterative, with tuples)
main (parms):+
lim =: string parms[1] as integer else 100
fp =: 0, 1
?# i =: from 1 upto lim
print i, fp.1
fp =: fp.2, fp.1 + fp.2
print i, fp.2

View file

@ -0,0 +1,11 @@
\ Fibonacci numbers (recursive)
\+ stdlib
fibo (n):
? n < 2
:> n
:> (fibo n - 1) + fibo n - 2 \ not: fibo(n-1) + fibo(n-2) == fibo (n - 1 + fibo (n-2)
main (parms):+
lim =: string parms[1] as integer else 30
?# i =: from 1 upto lim
print i, fibo i