Advertisement
paulogp

9 digit pandigital number

Sep 12th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. function is9Pandigital(num)
  2.     -- 9 digit zeroless pandigital
  3.     -- pandigital number is an integer that in a given
  4.     -- base has among its significant digits each digit
  5.     -- used in the base at least once
  6.     numSize = string.len(num)
  7.     result = false
  8.    
  9.     if numSize == 9 then
  10.         auxi = {}
  11.         for i = 1, numSize do
  12.             table.insert(auxi, tonumber(string.sub(num, i, i)))
  13.         end
  14.        
  15.         table.sort(auxi)
  16.        
  17.         sfinal = ""
  18.         for i = 1, #auxi do
  19.             sfinal = sfinal .. auxi[i]
  20.         end
  21.  
  22.         if sfinal == "123456789" then
  23.             result = true
  24.         end
  25.     end
  26.    
  27.     return result
  28. end
  29.  
  30. print(is9Pandigital(932465781))
  31. -- 932465781: true
  32. -- 992465781: false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement