Created
June 1, 2016 21:36
-
-
Save robwilliams/2d1bf8a0f0c0cd2d1d17cbba8cfb6772 to your computer and use it in GitHub Desktop.
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
defmodule Chop do | |
def guess(actual, range = low..high) do | |
_guess(actual, div(low+high, 2), range) | |
end | |
defp _guess(actual, actual, _) do | |
"YOU GOT IT #{actual} it is!" | |
end | |
defp _guess(actual, attempt, low.._) when actual < attempt do | |
guess(actual, low..attempt-1) | |
end | |
defp _guess(actual, attempt, _..high) when actual > attempt do | |
guess(actual, attempt+1..high) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment