Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created February 10, 2017 20:17
Show Gist options
  • Save gr33n7007h/646ce2c20a7258ecb6f73e60aeffc390 to your computer and use it in GitHub Desktop.
Save gr33n7007h/646ce2c20a7258ecb6f73e60aeffc390 to your computer and use it in GitHub Desktop.
codewars reverse or rotate
#!/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