0

I have this program,which I am running from the command line, that freezes after this method.This method works but at the end it freezes,and I am left with a constantly flashing cursor.

def self.chooseteams(numberofteams)
  i=1
  while i<numberofteams
    puts "choose a team"
    team=gets.chomp
    @@c<<team
    i+=1
  end
end

The program then freezes and fails to call the next method which is.It is meant to perform its function and when the condition is met,pass on to the next method.My guess is that it is caught in a infinite loop,however,I can't see it!

def self.secondfixer(numberofteams)
  until @@listofDrawnTeams.length==numberofteams do 
    firstPick = @@c.sample
    @@listofDrawnTeams<<firstPick
    @@listofDrawnTeams.uniq!
  end
end

The methods are all called at the end of the program

Genfix.gener(64)
Genfix.fixer(64)
Genfix.chooseteams(32)
Genfix.secondfixer(32)
Genfix.fixer(32)
DGM
  • 26,629
  • 7
  • 58
  • 79

1 Answers1

0

In your method secondfixer, your until loop might not ever complete if you have duplicate teams.

Using @@ variables is really odd - it's rarely used in ruby programming.

DGM
  • 26,629
  • 7
  • 58
  • 79
  • @@listofDrawnTeams.uniq! gets rid of the duplicates though so I don't think I have that problem.The @@ class variable is what I use for classes – user3739465 Jan 12 '15 at 00:26
  • But if your original samples have duplicates, it may never fill the new array. If you are trying to shuffle the array, try http://stackoverflow.com/questions/1816378/how-to-randomly-sort-scramble-an-array-in-ruby – DGM Jan 12 '15 at 15:05