RosettaCodeData/Task/Equilibrium-index/DuckDB/equilibrium-index.duckdb
2025-08-11 18:05:26 -07:00

15 lines
368 B
Text

create or replace function equilibrium_indices(lst) as table (
with recursive cte as (
select 0 as ix, 0 as before, 0 as pivotor, list_sum(lst) as after
union all
select ix+1,
before+pivotor,
lst[ix+1],
after - lst[ix+1]
from cte
where ix<length(lst)
)
select ix
from cte
where before = after and ix>0
);