Created
June 22, 2017 14:36
-
-
Save matsubara0507/9570ed26767ed841260a351a2e0d5bdd to your computer and use it in GitHub Desktop.
This file contains 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
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