global found dig[] .
proc test . .
   for i to len dig[]
      n = n * 10 + dig[i]
   .
   for i to len dig[]
      if n mod dig[i] <> 0
         return
      .
   .
   found = 1
   print n
.
len use[] 9
proc perm pos . .
   if found = 1
      return
   .
   for i = 9 downto 1
      dig[pos] = i
      if use[i] = 0
         use[i] = 1
         if pos = len dig[]
            test
         else
            perm pos + 1
         .
         use[i] = 0
      .
   .
.
for ndig = 9 downto 1
   len dig[] ndig
   perm 1
.
