Created
November 5, 2012 23:42
-
-
Save nsfyn55/4021173 to your computer and use it in GitHub Desktop.
Smallest Pandigital
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object App { | |
def main(args: Array[String]){ | |
val res = for(i <- 123 to 987 if isPanDigital(split(i)); | |
k <- 1000-i to 987 | |
if isPanDigital(split(i)++split(k)++split(i+k)))yield((i,k)) | |
println(res) | |
} | |
def isPanDigital(ls: List[Int]) = { | |
ls.size == ls.toSet.size | |
} | |
def split(n: Int) = if(n==0) List(0) else{ | |
(Stream.iterate(n)(_/10)takeWhile(_!=0)map(_%10)toList)reverse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment