From: Daniel Moore Date: 2009-06-13T01:56:11+09:00 Subject: [QUIZ] Matrix Rotator (#209) --00504502c54ccc400e046c299521 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have elapsed from the time this message was sent. 2. Support Ruby Quiz by submitting ideas and responses as often as you can! Visit: http://rubyquiz.strd6.com/suggestions 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. RSS Feed: http://rubyquiz.strd6.com/quizzes.rss -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ## Matrix Rotator (#209) Здравствуйте Rubyists, This week's quiz is write ruby method that will rotate a matrix 90 degrees counter-clockwise (or π/2 radians). Ex: 0 0 0 0 0 X 0 0 X X X 0 0 0 0 0 0 0 0 0 0 0 X 0 0 X X 0 0 0 X 0 I have attached the following test suite for your convenience: require 'test/unit' require 'solution' class RotationTest < Test::Unit::TestCase def test_square_rotation square = [ [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0] ] square_rotated = [ [0, 0, 0, 0], [0, 1, 1, 0], [1, 1, 0, 0], [0, 0, 0, 0] ] assert_equal Matrix.rotate(square), square_rotated end def test_rectangular_rotation rectangle = [ [0, 1, 0], [1, 1, 1] ] rectangle_rotated = [ [0, 1], [1, 1], [0, 1] ] assert_equal Matrix.rotate(rectangle), rectangle_rotated end end Have Fun! -- -Daniel http://rubyquiz.strd6.com P. S. This may come in handy on a future quiz. --00504502c54ccc400e046c299521 Content-Type: application/x-gzip; name="209-test.tar.gz" Content-Disposition: attachment; filename="209-test.tar.gz" Content-Transfer-Encoding: base64 X-Attachment-Id: f_fvub1su50 H4sICFXDMUoAAzIwOS10ZXN0LnRhcgDtlUtvwjAMgHvur7C0A0OqIC4t1dB22nmXiZ3QhDIaoFIp kKTafv6SvgQdCHbopmn+1Dat87Bj147P7oZOxzBDFIa2xShkh22Ng+hjMAoYhoHDkI1HoQNh14ZZ cqW5BHBiniUiPT/uUv8fxTfxV9s018k2G8i3TnTYAI+D4Gz80Y+a+PuIJv4jNmIOsE6safHP479I uVLwxLVMPlyAWCxBiXQ5kFvNtbjdFB190wNwA9N1osBc72shBei1gA1fJQtY891OZMqMElns2vu3 t0Vcic3/ItYm/+daKN1BEbiQ/4iRX+c/BqHN/4CNfcr/n0CKfZ6YZO7Z2A/zLNE9t5HVB0PPdcs6 8Vz9KVMzGO7BNpPJi5k0mdj3R65EVUTscnO1z7kU8/r/KqpIKYMHmBWfADPmAXpgnuzVO5ZhW8ZO y4q5hah8HigqlYu4pZBdoxBPG3ZOoXGQkHpunMfTqqLWZbS0pe+1jKoKZjG/cZoUC82zVZ5yeey5 qiM95by20fjFumb2GY/g8RLHnvnOXhtFZrtflNIRQRAEQRAEQRAEQRAEQRAEQRAEQRAE0RGfJdK6 CAAoAAA= --00504502c54ccc400e046c299521--