import Foundation
// A pandigital number is an integer that contains each digit from 0 to 9
// at least once, with the condition that the leading digit must be nonzero
// for example, 1023456987 is a pandigital number
func isPandigitalRange(_ num: Int, start: Int = 1, end: Int = 9) -> Bool {
let str = String(num)
// Build the expected digit string
let expected = (start...end).map { String($0) }.joined()
// Sort digits of the number
let sorted = str.sorted().map(String.init).joined()
return sorted == expected
}
print(isPandigitalRange(123456789))
print(isPandigitalRange(1023456789, start: 0, end: 9))
print(isPandigitalRange(987654321))
print(isPandigitalRange(123456780))
print(isPandigitalRange(123456780))
print(isPandigitalRange(123455789))
print(isPandigitalRange(12345))
/*
run:
true
true
true
false
false
false
false
*/