Permalink
Browse files

Solved problem 004

  • Loading branch information...
bbucko committed Jan 29, 2012
1 parent a533d66 commit c1079d4e3e6b6e2002ae5600887f2d9826a1e36b
@@ -0,0 +1,23 @@
+package pl.iogreen.euler
+
+class Problem004 {
+
+
+ def isPalindrom(s: String): Boolean = {
+ s.equals(s.reverse)
+ }
+
+ def resolve(min: Int, max: Int): Int = {
+ var maxValue = 0
+ for (i <- min to max) {
+ for (j <- min to max) {
+ val result = i * j
+ if (isPalindrom(result.toString) && result > maxValue) {
+ maxValue = result
+ }
+ }
+ }
+ maxValue
+ }
+
+}
@@ -0,0 +1,26 @@
+package pl.iogreen.euler
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.FunSuite
+
+@RunWith(classOf[JUnitRunner])
+class Problem004Test extends FunSuite {
+
+ val resolver = new Problem004()
+
+ test("is palindrome") {
+ assert(resolver.isPalindrom("9009") === true)
+ assert(resolver.isPalindrom("90009") === true)
+ assert(resolver.isPalindrom("9001009") === true)
+ assert(resolver.isPalindrom("9102019") === true)
+
+ assert(resolver.isPalindrom("900119") === false)
+ }
+
+ test("test resolver") {
+ assert(resolver.resolve(10, 99) === 9009)
+ assert(resolver.resolve(100, 999) === 906609)
+ }
+
+}

0 comments on commit c1079d4

Please sign in to comment.