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

  1. #include <stdio.h>
  2.  
  3. main()
  4. {
  5.       unsigned posn, avail;
  6.       unsigned long n;
  7.       unsigned long pow10[] = {
  8.             1L, 10L, 100L, 1000L, 10000L, 100000L,
  9.             1000000L, 10000000L, 100000000L};
  10.       unsigned long fill[] = {
  11.             123456789L, 12354678L, 1253467L, 152346L,
  12.             51234L, 1234L, 123L, 12L, 1L, 0L};
  13.       int I;
  14.  
  15. #ifdef TEST
  16.       for (I = 0; I < 200; ++I)
  17.       {
  18. #endif
  19.             for (n = 123456789L, posn = 1, avail = 0xfffe; posn < 10; ++posn)
  20.             {
  21.                   unsigned long div = pow10[9 - posn];
  22.                   unsigned long sub = n / div;
  23.                   unsigned dig = (unsigned)(sub % 10);
  24.  
  25.                   if (1 != posn)
  26.                   {
  27.                         unsigned long res = sub % posn;
  28.  
  29.                         if ((0L != res) || (0L == dig) ||
  30.                               ((dig & 1) != (posn & 1)) ||
  31.                               (!(avail & (1 << dig))))
  32.                         {
  33.                               n += (posn - res) * div;
  34.                               n -= n % div;
  35.                               n += fill[posn];
  36.                               dig = (unsigned)((n / 10000) % 10);
  37.                               if (5 != dig)
  38.                               {
  39.                                     n += ((dig > 5 ? 10 : 5) -
  40.                                           (dig % 5)) * 10000L;
  41.                               }
  42.                               posn = 0;
  43.                               avail = 0xfffe;
  44.                               continue;
  45.                         }
  46.                   }
  47.                   avail &= ~(1 << dig);
  48.             }
  49. #ifdef TEST
  50.       }
  51. #endif
  52.       printf("Number = %lu\n", n);
  53.       return 0;
  54.