Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object RevRot {
- def revRot(strng: String, sz: Int): String = {
- def isDivisible(s: String): Boolean = s.map[Int](x => x.toInt).map(x => x * x * x).sum % 2 == 0
- def rotate(s: String): String = s.drop(1) + s.head
- if (sz > strng.length || sz <= 0 || strng.length == 0) ""
- else strng.grouped(sz).filter(_.length == sz).map(x => if (isDivisible(x)) x.reverse else rotate(x)).mkString
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement