You are viewing a single comment's thread. Return to all comments →
Wow. This is beautiful... My first solution looked ugly like:
def swapPairs(str : String) = { val (even, odd) = str.zipWithIndex .partition( x => x._2 % 2 == 0) even.zip(odd) .map{ case ((a,b),(c,d)) => s"$c$a" } .mkString }
then I improved to:
def swapPairs(str : String) = { str.grouped(2) .map(x => s"${x.tail}${x.head}" ) .mkString }
String-o-Permute
You are viewing a single comment's thread. Return to all comments →
Wow. This is beautiful... My first solution looked ugly like:
then I improved to: