Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
Created March 29, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJFaraday/95539471cf0c8dd3060aae9d89552bf4 to your computer and use it in GitHub Desktop.
Save AJFaraday/95539471cf0c8dd3060aae9d89552bf4 to your computer and use it in GitHub Desktop.
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