Last active
December 15, 2015 13:58
-
-
Save ecmelkytz/5270551 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!usr/bin/ruby | |
#encoding: utf-8 | |
#Kullanicinin girdigi sayiyi bilgisayarin tahmin etmesi | |
puts "Oyun oynamak icin 0-100 arasi bir sayi giriniz" | |
sayi = gets | |
tahmin_sayisi = 1 | |
a, b = 0, 100 | |
s = Random.new | |
tahmin = s.rand(a..b) | |
while 1 | |
if sayi.to_i == tahmin | |
puts "Bilgisayar #{tahmin_sayisi} kerede sayiyi buldu" | |
break | |
elsif sayi.to_i > tahmin | |
puts "Kucuk bir tahmin oldu.Tahmin: #{tahmin}" | |
a = tahmin + 1 | |
tahmin = s.rand(a..b) | |
tahmin_sayisi += 1 | |
elsif sayi.to_i < tahmin | |
puts "Buyuk bir tahmin oldu.Tahmin: #{tahmin}" | |
b = tahmin - 1 | |
tahmin = s.rand(a..b) | |
tahmin_sayisi += 1 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment