Created
March 29, 2018 15:10
-
-
Save AJFaraday/95539471cf0c8dd3060aae9d89552bf4 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
class DumbSearch | |
def initialize(min, max) | |
#@min = min | |
#@max = max | |
@guessed = false | |
@next_guess = 50 | |
end | |
attr_reader :next_guess, :guessed | |
def go(result) | |
return if @guessed | |
case result | |
when :right | |
@guessed = true | |
when :lower | |
@next_guess -= 1 | |
when :higher | |
@next_guess += 1 | |
end | |
end | |
private | |
def update_next_guess | |
@next_guess = (@max + @min) / 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment