Skip to content

Instantly share code, notes, and snippets.

@nsfyn55
Created November 5, 2012 23:42
Show Gist options
  • Save nsfyn55/4021173 to your computer and use it in GitHub Desktop.
Save nsfyn55/4021173 to your computer and use it in GitHub Desktop.
Smallest Pandigital
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