Skip to content

Instantly share code, notes, and snippets.

@kachick
Created January 24, 2012 17:48
Show Gist options
  • Save kachick/1671481 to your computer and use it in GitHub Desktop.
Save kachick/1671481 to your computer and use it in GitHub Desktop.
Guess number
# an approach to
# * http://vipprog.net/wiki/exercise.html#d082e883
# tested Ruby 1.9.3
$VERBOSE = true
right = rand 100
loop do
puts "Can you guess the number that I'm thinking of?"
case Integer(gets)
when right
puts 'Great!'
break
when ->answer{answer < right}
puts 'small'
when ->answer{answer > right}
puts 'big'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment