Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
27
Task/Hailstone-sequence/DuckDB/hailstone-sequence.duckdb
Normal file
27
Task/Hailstone-sequence/DuckDB/hailstone-sequence.duckdb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Generate the hailstone sequence without an index
|
||||
create or replace function hailstone(start) as table (
|
||||
with recursive cte as (
|
||||
select start as n
|
||||
union all
|
||||
select if( n % 2 = 0, n // 2, 3 * n + 1) as n
|
||||
from cte
|
||||
where n != 1
|
||||
) from cte
|
||||
);
|
||||
|
||||
# The length of the hailstone sequence of nn using count()
|
||||
create or replace function hailstone_length(nn) as (
|
||||
select count() as n from hailstone(nn)
|
||||
);
|
||||
|
||||
# Return a tuple giving the seed and the hailstone sequence length
|
||||
create or replace function hailstone_max_of_lengths(mx) as (
|
||||
select max_by( (n,hailstone_length(n)), hailstone_length(n))
|
||||
from range(1,mx+1) _(n)
|
||||
);
|
||||
|
||||
# Table of lengths (e.g. for use with histogram())
|
||||
create or replace function hailstone_lengths(mx) as table (
|
||||
select hailstone_length(n) as length
|
||||
from range(1,mx+1) _(n)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue