Created
January 7, 2016 00:38
-
-
Save jcamenisch/26609658a5038f5d4fb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, low..high) do | |
n = div(low + high, 2) | |
IO.puts "Is it #{n}?" | |
_next_guess(actual, low..high, n) | |
end | |
defp _next_guess(actual, _.._, actual) do | |
actual | |
end | |
defp _next_guess(actual, low.._, n) when n > actual do | |
guess(actual, low..n) | |
end | |
defp _next_guess(actual, _..high, n) when n < actual do | |
guess(actual, n..high) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment