home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / tpchal_1.zip / MR.C < prev    next >
C/C++ Source or Header  |  1994-05-26  |  1KB  |  49 lines

  1. #include <stdio.h>
  2.  
  3. int main (void)
  4. {
  5.       long Number;
  6.       int Digit, Used, Bit, Position;
  7. #ifdef TEST
  8.       int I;
  9.  
  10.       for (I = 0; I < 1000; ++I)
  11.       {
  12. #endif
  13.             Number = 0L;
  14.             Digit = Used = 0;
  15.             Bit = Position = 1;
  16.             while (1)
  17.             {
  18.                   while (Digit++ < 9)
  19.                   {
  20.                         if ((Used & (Bit <<= 1)) == 0)
  21.                               break;
  22.                   }
  23.                   if (Digit > 9)
  24.                   {
  25.                         Used &= ~(Bit = 1
  26.                               << (Digit = (int) ((Number /= 10) % 10)));
  27.                         Number -= Digit;
  28.                         Position--;
  29.                         continue;
  30.                   }
  31.                   if (((Number += Digit) % Position) != 0)
  32.                   {
  33.                         Number -= Digit;
  34.                         continue;
  35.                   }
  36.                   if (++Position > 9)
  37.                         break;
  38.                   Number *= 10;
  39.                   Used |= Bit;
  40.                   Digit = 0;
  41.                   Bit = 1;
  42.             }
  43. #ifdef TEST
  44.       }
  45. #endif
  46.       printf ("\nNumber = %li\n", Number);
  47.       return 0;
  48. }
  49.