Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reverseInt(x: Int): Int = {
- x.toString.reverse.toInt
- }
- def palindromeNumberEquation(x:Int, y:Int): Boolean = {
- reverseInt(x) == x*y
- }
- def palindromeNumber(x:Int): Boolean = {
- palindromeNumberEquation(x, 1)
- }
- //@TailRecursive
- def findFirstNumberSolvingEquation(x:Int, y:Int): Boolean = {
- palindromeNumberEquation(x, y) match {
- case true => println("Number x= " + x + " * 4 = " + reverseInt(x))
- true
- case false => findFirstNumberSolvingEquation(x+1, y)
- }
- }
- findFirstNumberSolvingEquation(11,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement