??? 12/20/06 22:31 Read: times |
#129858 - here you are Responding to: ???'s previous message |
Comments deliberately omitted, not to spoil all the fun of founding out how is it working... :-)))
Have fun! JW (the C hater) /* --- The following code comes from c:\lcc\lib\wizard\textmode.tpl. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int ptr[17]; int a[65536]; void generate_blah(int nmax) { int i, j, k, l, m, n, p, tmp; n = 1; ptr[0] = 0; a[0] = 0; ptr[1] = 1; a[1] = 1; ptr[2] = 2; do { k = 1 << (2 * n); for (m = (2*n) + 1; m > 0; ) { p = k; m--; for (l = n + 1; l > 0; ){ l--; if ( (l <= m) && ((m - l) <= n) ) { for (j = ptr[l + 1] - 1; j >= ptr[l]; j--) { tmp = m - l + 1; for (i = ptr[tmp] - 1; i >= ptr[m - l]; i--) { a[--k] = (a[j] << n) + a[i]; } } } } ptr[m+1] = p; } n = n * 2; } while (n < nmax); } int main(void) { int i, j, k, n; n = 16; generate_blah(n); k = 1 << n; for (i = n; i >= 0 ; i--) { printf("%2d: ", i); for (j = ptr[i+1]-1; j >= ptr[i]; j--) { printf("%04X ", a[--k]); } printf("\n"); } return(0); } |