I know two arrays can be zipped and the result can be iterated with #each. But how do you do it with an unknown number of enumerables? Let's say
anand = %w(1-0 0.5-0.5 0.5-0.5 1.0)
carlsen = %w(0-1 0.5-0.5 0.5-0.5 1.0)
kramnik = %w(0.5-0.5 0.5-0.5 0.5-0.5 1.0)
players= [anand, carlsen, kramnik]
#something smart
players.each{|round|puts round} #first line should be "1-0 0-1 0.5-0.5"
players.transpose.map {|a| a.join(" ")}
anand.zip(carlsen, kramnik) do |round| puts round.join(" ") end
This will print:
1-0 0-1 0.5-0.5
0.5-0.5 0.5-0.5 0.5-0.5
0.5-0.5 0.5-0.5 0.5-0.5
1.0 1.0 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With