Created
February 10, 2017 20:17
-
-
Save gr33n7007h/646ce2c20a7258ecb6f73e60aeffc390 to your computer and use it in GitHub Desktop.
codewars reverse or rotate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def revrot(str, sz) | |
return "" if str.empty? or sz.zero? | |
str.chars.each_slice(sz).______ do |chunk| | |
chunk.size == sz | |
end.___ { |ch| ch.___(&:to_i) }.___ do |chunk| | |
if chunk.___ { |int| (int ** 3) }.___.modulo(2).zero? | |
chunk.reverse | |
else | |
chunk.rotate(1) | |
end | |
end.____ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment