#!/usr/bin/perl

@bad_guess=();

print "enter a number\n";
$answer=<STDIN>; chomp($answer);


# While the number of unique guesses is less than 5, keep guessing
while ( $#bad_guess < 5 ){

	# Generate random number from 1 to 10
 	$guess=int(rand(10));
	
 	# Show output of what the number is and what our answer is.	
	print "\nI input $answer\tComputer chose $guess\n";
	
	# Did the computer guess the user's answer?
	if ( "$answer" =~ "$guess" ){
		print "Computer Guessed the number\n";
		exit 0;
	} else {
	# Since computer didn't guess correctly, see if it was guessed before.
	# My problem with this is that the array of missed guesses is empty when I start, 
	# so the foreach statement is never entered.
		foreach $string (@bad_guess){	
			if ( "$guess" =~ "$string" ){
				print "Already chose that number\n";
				return;
			} else {
				print "That was a new guess\n";
				push ( @bad_guess, $guess );
				return
			}
		}
	}
}
