Skip to content

Instantly share code, notes, and snippets.

@craftninja
Created May 17, 2014 16:36
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 craftninja/b5d82084bb79ca428c95 to your computer and use it in GitHub Desktop.
Save craftninja/b5d82084bb79ca428c95 to your computer and use it in GitHub Desktop.
This is a pre-gSchool NumberStumper iteration. Apparently I finished this on my birthday in 2013.
puts 'BWAAAAAAAA'
puts 'Number Stumper, Level Infinity'
puts 'Please enter the number of digits you are interested in guessing for:'
digits = gets.chomp.to_i
numguess=0
lowlim = 10**(digits-1)
uplim = 10**digits - 1
count = 1
randnum = []
randnum.push (rand(9)+1)
while count != digits
count=count +1
randnum.push rand(10)
end
puts 'Please guess your number'
while true
guess = gets.chomp.to_i
numguess=numguess+1
while guess < lowlim || guess >uplim
puts 'Hmmmm... that\'s not really the right amount of numbers, now is it... guess again'
guess = gets.chomp.to_i
end
count = digits
guessnum = []
while count != 0
top = 10**count
bottom = 10**(count-1)
guessnum.push (guess%top)/bottom
count = count -1
end
if randnum.join == guessnum.join
puts 'OMG you totally win!'
puts 'you guessed that in '+ numguess.to_s + ' tries.'
break
end
count = 0
count2 = 0
numright = 0
numwrplace = 0
randnumcount = []
while count != digits
while count2 != digits
if count == count2 && randnum[count] == guessnum[count2]
numright = numright + 1
randnumcount[count] = 'counted'
end
count2 = count2+1
end
count = count +1
count2 = 0
end
count = 0
count2 = 0
while count != digits
while count2 != digits
if count != count2 && randnum[count] == guessnum[count2] && randnumcount[count] != 'counted'
numwrplace = numwrplace + 1
randnumcount[count] = 'counted'
end
count2 = count2+1
end
count = count+1
count2 = 0
end
puts 'number right: ' + numright.to_s
puts 'number in wrong place: ' + numwrplace.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment