Skip to content

Instantly share code, notes, and snippets.

@jooeycheng
Last active July 5, 2016 09:27
Show Gist options
  • Save jooeycheng/44b514249ddabb55d75a1943d238e1af to your computer and use it in GitHub Desktop.
Save jooeycheng/44b514249ddabb55d75a1943d238e1af to your computer and use it in GitHub Desktop.
Solutions to some of Codility Lessons
# === [Lesson 2: Arrays] - CyclicRotation
# === Program v1 (recursive)
def solution(a, k)
return a if k == 0 || a.length == 0
a = a.unshift(a.delete_at(a.length - 1))
k -= 1
return solution(a, k)
end
# === Program v2 (iterative)
def solution(a, k)
while k > 0 && a.length > 0
a = a.unshift(a.delete_at(a.length - 1))
k -= 1
end
return a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment