Solving Matrix with a simple ruby Script