Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
int delegate(in int) nothrow ffr, ffs;
|
||||
|
||||
nothrow static this() {
|
||||
auto r = [0, 1], s = [0, 2];
|
||||
|
||||
ffr = (in int n) nothrow {
|
||||
while (r.length <= n) {
|
||||
immutable int nrk = r.length - 1;
|
||||
immutable int rNext = r[nrk] + s[nrk];
|
||||
r ~= rNext;
|
||||
foreach (immutable sn; r[nrk] + 2 .. rNext)
|
||||
s ~= sn;
|
||||
s ~= rNext + 1;
|
||||
}
|
||||
return r[n];
|
||||
};
|
||||
|
||||
ffs = (in int n) nothrow {
|
||||
while (s.length <= n)
|
||||
ffr(r.length);
|
||||
return s[n];
|
||||
};
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio, std.array, std.range, std.algorithm;
|
||||
|
||||
iota(1, 11).map!ffr.writeln;
|
||||
auto t = iota(1, 41).map!ffr.chain(iota(1, 961).map!ffs);
|
||||
t.array.sort().equal(iota(1, 1001)).writeln;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import std.stdio, std.array, std.range, std.algorithm;
|
||||
|
||||
struct ffr {
|
||||
static r = [int.min, 1];
|
||||
|
||||
static int opCall(in int n) nothrow {
|
||||
assert(n > 0);
|
||||
if (n < r.length) {
|
||||
return r[n];
|
||||
} else {
|
||||
immutable int ffr_n_1 = ffr(n - 1);
|
||||
immutable int lastr = r[$ - 1];
|
||||
// Extend s up to, and one past, last r.
|
||||
ffs.s ~= iota(ffs.s[$ - 1] + 1, lastr).array;
|
||||
if (ffs.s[$ - 1] < lastr)
|
||||
ffs.s ~= lastr + 1;
|
||||
// Access s[n - 1] temporarily extending s if necessary.
|
||||
immutable size_t len_s = ffs.s.length;
|
||||
immutable int ffs_n_1 = (len_s > n) ?
|
||||
ffs.s[n - 1] :
|
||||
(n - len_s) + ffs.s[$ - 1];
|
||||
immutable int ans = ffr_n_1 + ffs_n_1;
|
||||
r ~= ans;
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ffs {
|
||||
static s = [int.min, 2];
|
||||
|
||||
static int opCall(in int n) nothrow {
|
||||
assert(n > 0);
|
||||
if (n < s.length) {
|
||||
return s[n];
|
||||
} else {
|
||||
foreach (immutable i; ffr.r.length .. n + 2) {
|
||||
ffr(i);
|
||||
if (s.length > n)
|
||||
return s[n];
|
||||
}
|
||||
assert(false, "Whoops!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
iota(1, 11).map!ffr.writeln;
|
||||
auto t = iota(1, 41).map!ffr.chain(iota(1, 961).map!ffs);
|
||||
t.array.sort().equal(iota(1, 1001)).writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue