From: Harry Kakueki Date: 2013-07-18T12:49:24+09:00 Subject: Re: Get part of matrix --047d7b6d7d3a89460504e1c118a0 Content-Type: text/plain; charset=ISO-8859-1 > > > > Does your matrix always have these values in these locations? If so, maybe you do not need a matrix. def get_around(t) k = [-11,-10,-9,-1,1,9,10,11] k.map{|z| t+z}.select{|f| (t%10-f%10).abs<2 && f>=10 && f<=99} end p get_around(54) #> [43, 44, 45, 53, 55, 63, 64, 65] p get_around(40) #> [30, 31, 41, 50, 51] I have not verified the output for every case. You can do that if you are interested in this approach. Harry --047d7b6d7d3a89460504e1c118a0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
=A0


Does your matrix always ha= ve these values in these locations?
If so, maybe you do not n= eed a matrix.



=A0def get_around(t)
=A0 k =3D [-11,-10,-9,= -1,1,9,10,11]
=A0 k.map{|z| t+z}.select{|f| (t%10-f%10).abs<2 && f>=3D10 &a= mp;& f<=3D99}
end

p get_around(54) #> [43, 44, 45, 53, = 55, 63, 64, 65]
p get_around(40) #> [30, 31, 41, 50, 51]


<= /div>
I have not verified the output for every case. You can do that if you = are interested in this approach.


Harry





--047d7b6d7d3a89460504e1c118a0--