Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:04
Show Gist options
  • Save jackliusr/51fcdbf0a5c108dedd4b to your computer and use it in GitHub Desktop.
Save jackliusr/51fcdbf0a5c108dedd4b to your computer and use it in GitHub Desktop.
hackerank The Love-Letter Mystery in Scala
import scala.collection.immutable.StringOps;
object Solution {
def main(args: Array[String]) {
val lines = io.Source.stdin.getLines().toList
for(line <- lines.drop(1))
{
val l = line;
var (first, tmpSecond) = l.splitAt(l.size /2 )
val second = if(first.length() != tmpSecond.length()) tmpSecond.drop(1).reverse
else tmpSecond.reverse
var charPairs = first.zip(second)
var changes = charPairs.foldLeft(0) ( (a, b) => a + math.abs( b._1.toInt - b._2.toInt))
println(changes)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment