#include <stdio.h>
#include <stdlib.h>

int base=2, max=0, cpt, silence=0;

void decompose(int z, int b, int m)
{ printf("\n");
  while ( m-- ) {
    printf("%d", z % b);
    z /= b;
    cpt++;
  }
}

void comptage(int z, int b, int m)
{ 
  while ( m-- ){
    z /= b;
    cpt++;
  }
}


void enumeration( int b, int m)
{ int i, lim = 1, z;
  for( i = 0; i < m; i++) lim *= b;
  lim--;
  cpt = 0;
  if (! silence ) 
    for( z = 0; z < lim; z++)
       decompose(z, b, m);
  else {
    for( z = 0; z < lim; z++)
      comptage(z, b, m);
    printf("\n%d %d %d", b, m, cpt);
  }
}

void usage( void )
{
  printf("\nusage:");
  printf("\n   -b:base"); 
  printf("\n   -m:max"); 
  printf("\n   -h:help"); 
  printf("\n   -s:silence");
  printf("\n");
  exit(1);
}

void option( char *str )
{ 
  if ( *str != '-') usage(); 
  str++;
  switch( *str) {
  case 'b': str++; base = atoi( str ); break; 
  case 's': silence = 1; break;
  case 'm': str++; max = atoi( str ); break;
  case 'h':
  default :usage();
  }
}

int main( int argc, char *argv[] )
{ int i, m;
  for( i = 1; i < argc; i++)
    option( argv[i] );

  for( m = 1; m <= max; m++)
    enumeration( base, m);

  printf("\n");
  return 0;
}
