From: "David A. Black" Date: 2009-01-22T03:32:09+09:00 Subject: Re: 10 numbers in between 2 numbers --1926193751-1899886704-1232562830=:1379 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1899886704-1232562830=:1379" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1899886704-1232562830=:1379 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Thu, 22 Jan 2009, jko170 wrote: > On Jan 20, 5:19=A0pm, Tim Hunter wrote: >> jko170 wrote: >>> On Jan 19, 10:05 pm, James Gray wrote: >>>> On Jan 19, 2009, at 9:58 PM, jko170 wrote: >> >>>>> How can I get an array of 10 numbers in between two numbers? >>>>> (1..500).to_a >>>> I guess it depends on which ten numbers you want, but here's one way: >> >>>> =A0>> (1..500).enum_for(:step, 50).to_a >>>> =3D> [1, 51, 101, 151, 201, 251, 301, 351, 401, 451] >> >>>> James Edward Gray II >> >>> Yeah, the end numbers need to be included in the array of 10. >> >> Requirements: 10 numbers, evenly distributed, first and last numbers in >> the array. >> >> require 'pp' >> >> first, last =3D ARGV[0].to_f, ARGV[1].to_f >> numbers =3D [] >> incr =3D (last - first) / 9.0 >> n =3D first >> 10.times do >> =A0 =A0numbers << n >> =A0 =A0n +=3D incr >> end >> pp numbers >> >> -- >> RMagick:http://rmagick.rubyforge.org/ > > Thank you very much Tim! Works perfectly. Awww, you didn't say the final array didn't have to contain integers :-) David --=20 David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com =3D> Independent, social wishlist management! --1926193751-1899886704-1232562830=:1379-- --1926193751-1899886704-1232562830=:1379--