Quick actions

cmd+k|ctrl+k

Navigation

Languages

String isRotationallySymmetric

Snippet info

Language

Scala

Visibility

public

Author

devernul

Created

2018-12-08T13:45:52Z

Updated

2018-12-08T13:45:52Z

object Main extends App {
 def isRAsync (str: String): Boolean = {
   if (str.length < 2) false
   else {
     val numbers = Map(
       '0' -> '0',
       '1' -> '1',
       '6' -> '9',
       '8' -> '8',
       '9' -> '6'
     )
     var isAsync = true
     for (i <- 0 until str.length/2) {
       val ch = str.charAt(i)
       numbers.isDefinedAt(ch) match {
         case true => if (ch != str.charAt(str.length-i-1) && numbers(ch) != str.charAt(str.length-i-1)) isAsync=false
         case false => if (ch != str.charAt(str.length-i-1)) isAsync=false
       }
     }
     isAsync
   }
 }
  println(isRAsync("121121"))
}
INFO