Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created May 13, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlyshk/2688697 to your computer and use it in GitHub Desktop.
Save onlyshk/2688697 to your computer and use it in GitHub Desktop.
package proj_euler
object Problem8 {
lazy val num = "7316717653133062491922511967442" +
"6574742355349194934969835203127" +
"7450632623957831801698480186947" +
"8851843858615607891129494954595" +
"0173795833195285320880551112540" +
"6987471585238630507156932909632" +
"9522744304355766896648950445244" +
"5231617318564030987111217223831" +
"1362229893423380308135336276614" +
"2828064444866452387493035890729" +
"62904915604407723907138105158593" +
"07960866701724271218839987979087" +
"92274921901699720888093776657273" +
"330010533678812202354218097512545" +
"40594752243525849077116705560136048" +
"39586446706324415722155397536978179" +
"778461740649551492908625693219784686" +
"224828397224137565705605749026140797" +
"2968652414535100474821663704844031998" +
"90008895243450658541227588666881164271" +
"71479924442928230863465674813919123162" +
"82458617866458359124566529476545682848" +
"91288314260769004224219022671055626321" +
"11110937054421750694165896040807198403" +
"850962455444362981230987879927244284909" +
"188845801561660979191338754992005240636" +
"8991256071760605886116467109405077541002" +
"25698315520005593572972571636269561882670" +
"428252483600823257530420752963450"
def prod(str : String) : Int ={
var num = str.toInt
// Very ugly solution
var num1 = num / 10000
var num2 = (num - (num1 * 10000)) / 1000
var num3 = ((num - (num2 * 1000)) - (num1 * 10000)) / 100
var num4 = ((num - (num2 * 1000) - (num3 * 100)) - (num1 * 10000)) / 10
var num5 = ((num - (num2 * 1000) - (num3 * 100)) - (num1 * 10000) - (num4 * 10))
return num1 * num2 * num3 * num4 * num5
}
def solve() : Int = {
var nums_list = num.sliding(5).toList
var max_num = nums_list.map(s => prod(s)).max
return max_num
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment