Skip to content

Instantly share code, notes, and snippets.

@zonble
Last active January 31, 2018 17:24
Show Gist options
  • Save zonble/e3905b61cde6f56f743ee28dc8771f91 to your computer and use it in GitHub Desktop.
Save zonble/e3905b61cde6f56f743ee28dc8771f91 to your computer and use it in GitHub Desktop.
import Foundation
func solution(_ n:Int) -> Int {
let sorted_n = "\(n)".sorted()
let i = Int(pow(Double(10), Double("\(n)".count)))
return Array(0...i).filter { "\($0)".sorted() == sorted_n }.count
}
print(solution(0))
print(solution(1))
print(solution(2))
print(solution(123))
print(solution(1132))
print(solution(99998))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment