Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
5
Task/Metallic-ratios/DuckDB/metallic-ratios-1.duckdb
Normal file
5
Task/Metallic-ratios/DuckDB/metallic-ratios-1.duckdb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
create or replace table metals as
|
||||
(select (row_number() over () - 1) as b, name
|
||||
from unnest(
|
||||
['Platinum', 'Golden', 'Silver', 'Bronze', 'Copper','Nickel', 'Aluminium', 'Iron', 'Tin', 'Lead']
|
||||
) _(name) );
|
||||
24
Task/Metallic-ratios/DuckDB/metallic-ratios-2.duckdb
Normal file
24
Task/Metallic-ratios/DuckDB/metallic-ratios-2.duckdb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# 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);
|
||||
28
Task/Metallic-ratios/DuckDB/metallic-ratios-3.duckdb
Normal file
28
Task/Metallic-ratios/DuckDB/metallic-ratios-3.duckdb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# ix serves both as a rowid and as the count of the number of
|
||||
# iterations required to achieve the corresponding ratio
|
||||
create or replace function metallic_ratio_to_quiescence(b) as (
|
||||
with recursive cte as (
|
||||
select
|
||||
-1::HUGEINT as ix,
|
||||
1::HUGEINT as previ,
|
||||
1::HUGEINT as i,
|
||||
1::HUGEINT as j,
|
||||
1::DOUBLE as prevratio,
|
||||
1::DOUBLE as ratio
|
||||
union all
|
||||
select
|
||||
ix+1,
|
||||
i as previ,
|
||||
j as i,
|
||||
i + b*j as j,
|
||||
ratio as prevratio,
|
||||
(i::DOUBLE / previ) as ratio
|
||||
from cte
|
||||
where (ix < 4 or prevratio != ratio)
|
||||
)
|
||||
select last((ix, ratio))
|
||||
from cte
|
||||
);
|
||||
|
||||
select b, name, metallic_ratio_to_quiescence(b)
|
||||
from metals;
|
||||
Loading…
Add table
Add a link
Reference in a new issue