[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Matrix Rotator (#209

Luke Cowell

6/16/2009 4:14:00 AM

My solution:

def self.rotate(rect)
rotated = []
rect.each_with_index do |row, irow|
row.reverse.each_with_index do |col, icol|
rotated[icol] ||= []
rotated[icol][irow] = col
end
end
rotated
end

It works by reversing the elements in the row and then swapping elements
in the x & y axis.

Luke
--
Posted via http://www.ruby-....