Posted 28 October 2014 - 02:35 PM
I made a guess the number "AI", and I was curious to find out the average number of guesses it takes for this AI to guess the correct number.
So I made this:
Any help?
So I made this:
avg = 0
l = 0
max = 100
min = 1
avgs = {}
--term.write("Enter a number between 1 100: ")
--input = tonumber(read())
for i = 1, 20 do
input = math.random(1, 100)
repeat
guess = math.random(min, max)
l = l+1
if guess < input then
min = guess
elseif guess > input then
max = guess
end
until guess == input
table.insert(avgs, l)
print("The number was "..guess..", and it took "..l.." guesses")
end
for k, v in pairs(avgs) do
avg = avg + v
avg = avg/20
end
print("The final average guesses: "..avg)
But this just runs the guessing AI twice and then pauses, and then throws and outOfBounds Exception.Any help?