Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def reverseInt(x: Int): Int = {
  2. x.toString.reverse.toInt
  3. }
  4.  
  5. def palindromeNumberEquation(x:Int, y:Int): Boolean = {
  6. reverseInt(x) == x*y
  7. }
  8.  
  9. def palindromeNumber(x:Int): Boolean = {
  10. palindromeNumberEquation(x, 1)
  11. }
  12.  
  13. //@TailRecursive
  14. def findFirstNumberSolvingEquation(x:Int, y:Int): Boolean = {
  15. palindromeNumberEquation(x, y) match {
  16. case true => println("Number x= " + x + " * 4 = " + reverseInt(x))
  17. true
  18. case false => findFirstNumberSolvingEquation(x+1, y)
  19. }
  20. }
  21.  
  22. findFirstNumberSolvingEquation(11,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement