Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function is9Pandigital(num)
- -- 9 digit zeroless pandigital
- -- pandigital number is an integer that in a given
- -- base has among its significant digits each digit
- -- used in the base at least once
- numSize = string.len(num)
- result = false
- if numSize == 9 then
- auxi = {}
- for i = 1, numSize do
- table.insert(auxi, tonumber(string.sub(num, i, i)))
- end
- table.sort(auxi)
- sfinal = ""
- for i = 1, #auxi do
- sfinal = sfinal .. auxi[i]
- end
- if sfinal == "123456789" then
- result = true
- end
- end
- return result
- end
- print(is9Pandigital(932465781))
- -- 932465781: true
- -- 992465781: false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement