Last active
August 29, 2015 14:25
-
-
Save coopermayne/d8bf67c2391e81c84c5d to your computer and use it in GitHub Desktop.
your work from today
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
###Guessing game | |
```ruby | |
puts"pick an integer number 1...100 and keep it in your head" | |
puts "NO TROLLOLLOLLOLLOLLOLLOLLOing" | |
puts "continue... ( press enter)" | |
gets | |
top = 1000 | |
bottom = 0 | |
counter = 0 | |
while true | |
system('clear') | |
numero = bottom + (top-bottom)/2 | |
counter += 1 | |
puts "my guess:" + numero.to_s | |
puts "did i guess rite | |
(type either lower=l,higher=h,or correct=c)" | |
guess=gets.chomp | |
if guess=='c' | |
system('clear') | |
puts "guesed it in " + counter.to_s | |
break | |
end | |
if guess=='l' | |
top = numero | |
end | |
if guess=='h' | |
bottom = numero | |
end | |
end | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment