Hi all,

I'm new to ruby, and I'm Having trouble with my code. It's an exercise for learning ruby, and I'm plowing through it. The explanation of the exercise is this:

For each person in your group, you want to assign a "spy" such that no one spies on themselves or someone with the same last name.

Input: A file you will name "people.txt" of the form:
Luke Skywalker <[email protected]>
Leia Skywalker <[email protected]>
John Wayne <[email protected]>
Clark Kent <[email protected]>
Lois Ken <[email protected]>
Pop Eye <[email protected]>
Private Eye <[email protected]>
Robotic Eye <[email protected]>
Vicki Allan <[email protected]>
Joe Allan <[email protected]>
Terrance Allan <[email protected]>
Philip Allan <[email protected]>

That's the text file I have to work with. It has all those random spacings in there for a reason, so it's a bit trickier to get the right input. Here's my implementation:

class People # Contains all information about a person
  attr_accessor :fname, :lname, :email, :found
  def initialize(fname, lname, email,found)
    @fname = fname
    @lname = lname
    @email = email
    @found = found
# This method gets all the names, and puts them in a string, line by line
def get_the_names()
  people_array = IO.readlines("people.txt")

#counts the lines in the file
count = 0
File.open("people.txt", 'r') { |fh|
  count += 1 while fh.gets

#the raw names, gotten from get_the_names()
raw_names = get_the_names()

#Takes the raw_names, strips them, and puts them into
#an array called "stripped"
stripped = Array.new(count)
count.times { |index|
  stripped[index] = raw_names[index].scan(/\w+/)

#make the array of People objects
spies = Array.new(count)
for i in 0..(count-1) do
  #this command re-creates the email address, because it was split into 3 parts
  email = "<" + stripped[i][2] + "@" + stripped[i][3] + "." + stripped[i][4] + ">"
  #0 will always be fname, and 1 will always be last name, which is why they're hard-coded
  spies[i] = People.new(stripped[i][0],stripped[i][1],email,false)

#perform some spying! Making sure no one spies on themselves,
#or someone with their same last name
r_spies = spies.sort_by{ rand }
rand_spies = r_spies.dup

found = 12
index = 0

while found > 0 do
  for k in 0..spies.length()-1 do
    for l in 0..rand_spies.length()-1 do
      if spies[k].lname == rand_spies[l].lname
      if spies[k].email.to_s == rand_spies[l].email.to_s
      if spies[k].found == true || rand_spies[l].found == true
      spies[k].found = true
      rand_spies[l].found = true
      puts "Person " + spies[k].fname.to_s + " " + spies[k].lname.to_s + " at " + spies[k].email.to_s + " spies on " + "Person " + rand_spies[l].fname.to_s + " " + rand_spies[l].lname.to_s + " at " + rand_spies[l].email.to_s
      found = found-1
The problem is this: It correctly spies on 6 people, but it hangs on an infinite loop after the 6th one, and I can't figure it out. Any help would be GREATLY appreciated.