------ art_145321_706780.1165957609726
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Its not quite as clean as I'd like but there are other things I should be
doing...
class Tournament
attr_reader :list
def initialize players
raise "Must be more than one player in the tournament!" if players < 2
@players layers
@list rray.new(players) { |i| i+1 }
# Add 'bye's up to the next power of 2
next_power ** sprintf("%b",players).length
unless players next_power / 2
(players+1).upto(next_power) { @list << 'bye' }
end
@list enerate @list
end
def generate list
len ist.length
return list if len <
left ist[0..(len/4-1)]+list[-(len/4)..-1]
right ist[(len/4)..-(len/4+1)]
[generate(left),generate(right)]
end
def to_s
lines ]
depth printf("%b",@list.flatten.length).length - 1
title "
1.upto(depth) { |r| title + printf( "R%d ", r ) }
lines << title
lines << ("