Last active
December 17, 2015 00:10
-
-
Save mbc9news/5519075 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
//http://euler.synap.co.kr/prob_detail.php?id=4 | |
//앞에서부터 읽을 때나 뒤에서부터 읽을 때나 모양이 같은 수를 대칭수(palindrome)라고 부릅니다. | |
// 두 자리 수를 곱해 만들 수 있는 대칭수 중 가장 큰 수는 9009 (= 91 × 99) 입니다. | |
// 세 자리 수를 곱해 만들 수 있는 가장 큰 대칭수는 얼마입니까? | |
class Euler_004 { | |
def getMaxPalindrome(numLength:Int):Int = { | |
val x = ("9"*numLength).toInt | |
val y = ("9"*numLength).toInt | |
var maxNum = 0 | |
for(x <- 1 to x){ | |
for(y <- 1 to y){ | |
val tNum = x*y | |
val tNumStr = tNum.toString() | |
val tNumlen = tNumStr.length() | |
if(tNumlen%2 == 0){ | |
if(tNumStr == tNumStr.reverse && tNum > maxNum){ | |
maxNum = tNum | |
} | |
} | |
} | |
} | |
return maxNum | |
} | |
} | |
object Euler_004 extends App { | |
println(new Euler_004().getMaxPalindrome(2)) | |
println(new Euler_004().getMaxPalindrome(3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment