Skip to content

Instantly share code, notes, and snippets.

@jrsconfitto
Created June 13, 2011 22:09
Show Gist options
  • Save jrsconfitto/1023844 to your computer and use it in GitHub Desktop.
Save jrsconfitto/1023844 to your computer and use it in GitHub Desktop.
Code Kata Two solutions
class Chop
def chop(target, values)
size = values.size
if size == 0
-1
elsif size == 1
(values[0] == target ? 0 : -1)
else
if target < values[size/2]
chop(target, values[0..size/2-1])
else
result = chop(target, values[size/2..size])
(result != -1 ? size/2 + result : -1)
end
end
end
end
@jrsconfitto
Copy link
Author

These are my attempts at CodeKata two solutions.

-The first is iterative
-The second is recursive
-The third (4th commit) is recursive and a little different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment