Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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);
}


List of 40 messages in thread
TopicAuthorDate
Looking for an algorithm.            01/01/70 00:00      
   I'd split it in two (or 4)            01/01/70 00:00      
      I've shown, in increseing detail, how to do it            01/01/70 00:00      
   Sorted, or only counted?            01/01/70 00:00      
      Counting is enough            01/01/70 00:00      
         Not sorting or counting then??            01/01/70 00:00      
            My approach.            01/01/70 00:00      
               Erik's idea is fast and simple!            01/01/70 00:00      
   did you even consider what I posted            01/01/70 00:00      
      I considered lookup tables.            01/01/70 00:00      
         look at my code it is right there            01/01/70 00:00      
         Can you explain your table?            01/01/70 00:00      
            Interpret it in binary            01/01/70 00:00      
               Hhm...            01/01/70 00:00      
                  Use of the table/algorithm            01/01/70 00:00      
                  misunderstanding            01/01/70 00:00      
                     Ah. I thought so.            01/01/70 00:00      
            explanation of table            01/01/70 00:00      
   table lookup            01/01/70 00:00      
   now, I'm confused            01/01/70 00:00      
      The keyword is "enumerate".            01/01/70 00:00      
         i give up since nobody can answer in english            01/01/70 00:00      
            Meaning #1            01/01/70 00:00      
               there must be some language problem here            01/01/70 00:00      
                  Basically, a)            01/01/70 00:00      
                     then this will work (and I believe the fastest)            01/01/70 00:00      
                        maybe yes            01/01/70 00:00      
                           maybe faster, but not6 what he ned            01/01/70 00:00      
                              it's sometimes not easy to describe what one needs            01/01/70 00:00      
                                 Sorting or counting            01/01/70 00:00      
                                    Bit shifting            01/01/70 00:00      
                                    I elaborated.            01/01/70 00:00      
                                       Christoph, have you tried...            01/01/70 00:00      
                                          It looks interesting ..            01/01/70 00:00      
                                             well, you said that...            01/01/70 00:00      
                                                here you are            01/01/70 00:00      
                                                   Works.            01/01/70 00:00      
                                                      compiler            01/01/70 00:00      
                                                         Benchmark            01/01/70 00:00      
                                                            thanks!            01/01/70 00:00      

Back to Subject List