24 lines
579 B
Text
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);
|