#include <stdio.h>

#define TARGET_COMBINATION 15

int main (int argc, char *argv[])
{
  unsigned int total_count = 0;
  unsigned int i;

  for (i = 0; i < 0xffffffff; ++i) /* for each CA rule */
  {
    int j;
    unsigned int bit = 1;
    int match_count = 0;

    for (j = 0; j < 32; ++j) /* TARGET_COMBINATION bits in rule? */
    {
      if (i & bit)
        match_count++;

      if (match_count > TARGET_COMBINATION)
        break;

      bit <<= 1;
    }

    if (match_count == TARGET_COMBINATION) /* show rule */
    {
      total_count++;
      printf("%x\n", i);
    }

  }

  printf("There are %u rules of %u bits\n", total_count, TARGET_COMBINATION);
	
  return 0;
}
