RosettaCodeData/Task/Metallic-ratios/DuckDB/metallic-ratios-2.duckdb
2025-08-11 18:05:26 -07:00

24 lines
579 B
Text

# The Lucas-like function as per the task description
create or replace function lucas(b, n) as table (
with recursive cte as (
select 1 as ix, 1::HUGEINT as i, 1::HUGEINT as j
union all
select
ix+1,
j as i,
i + b*j as j
from cte
where ix < n)
select ix, i
from cte
);
# The successive metallic ratio approximations
create or replace function metallic_ratio(b, n) as table (
select i / (lag(i) over ())
from lucas(b,n)
);
.maxwidth 200
select b, (select array_agg(i) from lucas(b, 15)) as "lucas-like"
from range(0, 10) _(b);