Created
February 2, 2016 21:26
-
-
Save eibrahim/4e0b464d8adac4b098bc to your computer and use it in GitHub Desktop.
Guess the number within a range
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
defp midpoint a,b do div(a+b,2) end | |
def guess(my_choice, a.._) when my_choice == a do IO.puts "is it #{a}?" end | |
def guess(my_choice, _..b) when my_choice == b do IO.puts "is it #{b}?" end | |
def guess(my_choice, a.._) when my_choice < a do IO.puts "out of range" end | |
def guess(my_choice, _..b) when my_choice > b do IO.puts "out of range" end | |
def guess(my_choice, a..b) when my_choice > div((a+b),2) do | |
IO.puts "is it #{midpoint(a,b)}?" | |
guess my_choice, midpoint(a,b)..b | |
end | |
def guess(my_choice, a..b) when my_choice < div((a+b),2) do | |
IO.puts "is it #{midpoint(a,b)}?" | |
guess my_choice, a..midpoint(a,b) | |
end | |
def guess(my_choice, a..b) when my_choice == div((a+b),2) do | |
IO.puts "i got it. it is #{midpoint(a,b)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment