32 lines
806 B
Text
32 lines
806 B
Text
# Table of up to `lim` gapful numbers in range(start, infinite)
|
|
create or replace function gapful(start, lim) as table (
|
|
with recursive cte as (
|
|
select start as i UNION ALL select i+1 as i
|
|
from cte
|
|
),
|
|
t as (
|
|
select i,
|
|
(i::varchar).regexp_extract_all('.') as s,
|
|
( s[1] || s[-1] )::integer as x
|
|
from cte
|
|
)
|
|
select i
|
|
from t
|
|
where i % x = 0
|
|
limit lim
|
|
);
|
|
|
|
create or replace function task(start, lim) as (
|
|
select array_agg(i order by i).array_to_string(' ') from gapful(start, lim)
|
|
);
|
|
|
|
.header off
|
|
.mode list
|
|
.print First 30 gapful numbers starting from 100:
|
|
select task(100, 30);
|
|
.print
|
|
.print First 15 gapful numbers starting from 1,000,000:
|
|
select task(1000000, 15);
|
|
.print
|
|
.print First 10 gapful numbers starting from 10^9:
|
|
select task(1000000000, 10);
|