Skip to content

Instantly share code, notes, and snippets.

@matsubara0507
Created June 22, 2017 14:36
Show Gist options
  • Save matsubara0507/9570ed26767ed841260a351a2e0d5bdd to your computer and use it in GitHub Desktop.
Save matsubara0507/9570ed26767ed841260a351a2e0d5bdd to your computer and use it in GitHub Desktop.
def radix(d: Int, n: Int): List[Int] = {
def loop(x: Int): List[Int] =
if (x == 0) Nil else { val a = x / d; val b = x % d; b :: loop(a) }
loop(n).reverse
}
def isPalin(ns: List[Int]): Boolean = ns == ns.reverse
def isMultiPalin(n: Int): Boolean =
(2 to n).toList.map(radix(_, n)).count(xs => xs.length > 2 && isPalin(xs)) >= 2
def solve(n: Int): Int = if (isMultiPalin(n)) n else solve(n+1)
println(List(1,399,99873).map(solve(_))) // List(17, 400, 99876)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment