Java 8+, 1044 bytes, sequence A008008 (Safe)
class c{long[]u={1,4,11,21,35,52,74,102,136,172,212,257,306,354,400,445,488,529,563,587,595,592,584,575,558,530,482,421,354,292,232,164,85,0,-85,-164,-232,-292,-354,-421,-482,-530,-558,-575,-584,-592,-595,-587,-563,-529,-488,-445,-400,-354,-306,-257,-212,-172,-136,-102,-74,-52,-35,-21,-11,-4,-1},v={0,0,0,0,0,0,0,0,0,0,0,0,-1,0,-1,0,-1,0,0,0,0,0,0,0,-1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,-1,0,0,0,0,0,0,0,-1,0,-1,0,-1,0,0,0,0,0,0,0,0,0,0,0,1},w={1,0,0,-1,5};long d=1,e=1;void f(long a,long b){long[]U=u,V=v,W,X;while(a-->0){U=g(U);w=h(v,w);}W=h(v,U);while(b-->0){V=g(V);v=h(v,v);}X=h(V,u);if(w[0]!=v[0]){int i,j,k=0;u=new long[i=(i=W.length)>(j=X.length)?i:j];for(;k<i;k++)u[k]=(k<i?W[k]:0)-(k<j?X[k]:0);d*=e++;}}long[]g(long[]y){int s=y.length,i=1;long[]Y=new long[s-1];for(;i<s;){Y[i-1]=y[i]*i++;}return Y;}long[]h(long[]x,long[]y){int q=x.length,r=y.length,i=0,j;long[]z=new long[q+r-1];for(;i<q;i++)if(x[i]!=0)for(j=0;j<r;)z[i+j]+=x[i]*y[j++];return z;}c(){f(3,0);System.out.println(u[0]/d);}public static void main(String[]args){new c();}}
Try it online!
Can be solved using a hidden string of size 12. Can definitely be golfed more, but there is no way this is actually winning. I just wanted to contribute out of respect for the number 8008.
Note: before anyone complains that the sequence is hard-coded, I've tested this up to the first term that diverges from the hard-coding (13th term = 307) and it gets it correctly albeit slowly. This is also why it's using long
instead of int
, otherwise it overflows before that term.
Update (Jul 12 2019): updated to be a bit more performant. Computes the 13th term in 30 seconds on my computer now instead of 5 minutes.
Update (Jul 17 2019): fixed bugs in for loop bounds for the g
function, and array length bounds in the bottom of the f
function. These bugs should have eventually caused problems, but not early enough to get caught by just checking the output. In either case, since the presence of these bugs 5 days into the game might have confused some people enough into being unable to solve this puzzle, I am totally fine with extending the "safe" deadline until July 24th for this submission.
Update (Jul 18 2019): After some testing I have confirmed that overflows start after the 4th term in the sequence and start affecting the validity of the output after the 19th term. Also in the program as it is written here, each consecutive term takes roughly 5 times longer than the previous to compute. The 15th term takes about 14 minutes on my computer. So actually computing the 19th term using the program as written would take over 6 days.
Also, here is the code with sane spacing/indentation so it is a bit easier to read if people don't have an IDE with auto-formatting on hand.
class c {
long[] u = {1, 4, 11, 21, 35, 52, 74, 102, 136, 172, 212, 257, 306, 354, 400, 445, 488, 529, 563, 587, 595, 592, 584,
575, 558, 530, 482, 421, 354, 292, 232, 164, 85, 0, -85, -164, -232, -292, -354, -421, -482, -530, -558, -575,
-584, -592, -595, -587, -563, -529, -488, -445, -400, -354, -306, -257, -212, -172, -136, -102, -74, -52, -35,
-21, -11, -4, -1},
v = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0,
0, 1, 0, 1, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
w = {1, 0, 0, -1, 5};
long d = 1, e = 1;
void f(long a, long b) {
long[] U = u, V = v, W, X;
while (a-- > 0) {
U = g(U);
w = h(v, w);
}
W = h(v, U);
while (b-- > 0) {
V = g(V);
v = h(v, v);
}
X = h(V, u);
if (w[0] != v[0]) {
int i, j, k = 0;
u = new long[i = (i = W.length) > (j = X.length) ? i : j];
for (; k < i; k++)
u[k] = (k < i ? W[k] : 0) - (k < j ? X[k] : 0);
d *= e++;
}
}
long[] g(long[] y) {
int s = y.length, i = 1;
long[] Y = new long[s - 1];
for (; i < s;) {
Y[i - 1] = y[i] * i++;
}
return Y;
}
long[] h(long[] x, long[] y) {
int q = x.length, r = y.length, i = 0, j;
long[] z = new long[q + r - 1];
for (; i < q; i++)
if (x[i] != 0)
for (j = 0; j < r;)
z[i + j] += x[i] * y[j++];
return z;
}
c() {
f(3, 0);
System.out.println(u[0] / d);
}
public static void main(String[] args) {
new c();
}
}
Solution
f(1,v[0]=1);
right before the System.out.println
The program works by computing the n'th Taylor expansion coefficient at 0. Where the original function is a quotient of polynomials, represented by u
and v
which I got from here, except that in the linked document the denominator is not multiplied out, and nowhere do they say that you have to compute the Taylor series, I stumbled on that by accident and then confirmed via another source.
The calculation is done via repeated application of the quotient rule for derivatives.
The incorrect first term of v
, the entire array w
and a few other things like the function f
having any arguments are thrown in to mess with people.