Skip to content

Commit

Permalink
Create Problem4.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
ditekunov authored May 27, 2018
1 parent fbcd78a commit c2a6128
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scala/Problem4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
object Main extends App {

def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0)*0.000000001 + "s")
result
}

//O(n^2)
time {
def palindrome (value: String) =
value.substring(0, value.length/2) == value.substring(value.length/2).reverse
def answer = (for (a <- 100 until 999 ; b <- 100 until 999
if palindrome(a * b toString))
yield a*b).max

print(answer)
}


}

0 comments on commit c2a6128

Please sign in to comment.