3 ms·
I made a joke posting to the comp.lang.c Usenet newsgroup on this topic. Looks like it was in 2014. https://groups.google.com/g/comp.lang.c/c/s7yeYGuMs8s/m/juw
by kazinator 4y ago
I made a joke posting to the comp.lang.c Usenet newsgroup on this topic. Looks like it was in 2014.
https://groups.google.com/g/comp.lang.c/c/s7yeYGuMs8s/m/juwf9wkVMnsJ https://groups.google.com/g/comp.lang.c/c/s7yeYGuMs8s/m/juwf...
Google Groups no longer allows "View Original". Let's reformat the code. Actually, nope; I found the file from 2014 easily.
Seventh degree polynomial for Fibonacci, with Easter egg:
#include <math.h>
#include <stdio.h>
int fib(int n)
{
double out = 0.002579370;
out *= n; out -= 0.065277776;
out *= n; out += 0.659722220;
out *= n; out -= 3.381944442;
out *= n; out += 9.230555548;
out *= n; out -= 12.552777774;
out *= n; out += 7.107142857;
out *= n;
return floor(out + 0.5);
}
int main(void)
{
int i;
for (i = 0; i < 9; i++) {
printf("fib(%d) = %d\n", i, fib(i));
switch (i) {
case 7:
puts("^ So, is this calculation fib or not?");
break;
case 8:
puts("^ Answer to life, universe & everything responds negatively!");
}
}
return 0;
}
Execution:
$ ./fib2
fib(0) = 0
fib(1) = 1
fib(2) = 1
fib(3) = 2
fib(4) = 3
fib(5) = 5
fib(6) = 8
fib(7) = 13
^ So, is this calculation fib or not?
fib(8) = 42
^ Answer to life, universe & everything responds negatively