Skip to content

Instantly share code, notes, and snippets.

@ecmelkytz
Last active December 15, 2015 13:58
Show Gist options
  • Save ecmelkytz/5270551 to your computer and use it in GitHub Desktop.
Save ecmelkytz/5270551 to your computer and use it in GitHub Desktop.
#!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