Palaiologos

fibonacci

Introduction

Lately I was working along with Ada#0132 on a small, multiprecision fibonacci sequence generator written in C. The final source code follows:

#define A m]
a[9999],*m=a;main(){for(2[A=4[A=1;;){for(;4[A;putchar(6[m-=3]+48));
for(puts(a);7[A;2[A=4[A,4[A=1)if(4[A+=3[m+=3]-1,9<(3[A=2[A+=3[A))++
5[A,7[A=1,3[A-=10;}}

The same algorithm, in a bit more readable form (preprocessed):

a[9999],*m=a;
main() {
  for(2[m]=4[m]=1;;) {
    for(; 4[m]; putchar(6[m-=3]+48));
    for(puts(a); 7[m]; 2[m]=4[m], 4[m]=1)
      if(4[m]+=3[m+=3]-1,9<(3[m]=2[m]+=3[m]))
        ++5[m],7[m]=1,3[m]-=10;
  }
}

Optimization

The algorithm can be optimized (mostly for speed) by setting the type of the memory array to unsigned char. The initial memory size can also be extended (infinitely, or maybe even dynamically allocated).

I'm open for suggestions on making it smaller (preferably, without altering the input buffer length). The goal was to make it fit inside a 160-character SMS message (but sadly, the code currently is 167 characters - it's 7 too many).