Skip to content

Instantly share code, notes, and snippets.

@angelworm
Created August 11, 2015 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelworm/5c163fb59b8573fc7054 to your computer and use it in GitHub Desktop.
Save angelworm/5c163fb59b8573fc7054 to your computer and use it in GitHub Desktop.
ideoneでSQLを使う+再帰
create table inputtmp (v integer);
create table input (i integer primary key autoincrement, v integer);
.separator X " "
.import /dev/stdin inputtmp
.headers on
.mode column
.separator "|" "\n"
delete from inputtmp limit 1;
insert into input select v from inputtmp;
with recursive
fib(i, a, b) as (
values(0, 0, 1)
union all
select i + 1, b % 1000 , (a + b) % 1000 from fib limit 100
),
bm(m, v) as (
values(2, 3)
union all
select m + 1, (v * v - 2) % 1000 from bm limit 100
),
max2m(p, k) as (
values(1, 0)
union all
select p * 2, (k + 1) from max2m limit 30
),
-- ans(ii, ani, n, an) as (
-- select i as ii, 1 as ani,
fib2(i, a, b) as (
values(0, 0, 1)
union all
select i + 1, b % 1000 , (a + b) % 1000 from fib2 limit 100
) select * from input;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment