From: Corey Haines Date: 2007-12-18T07:55:06+09:00 Subject: Re: dividing by two and rounding up Or, better yet require 'enumerator' irb(main):036:0> a.each_slice(3) do |slice| irb(main):037:1* puts slice.join(", ") irb(main):038:1> end 1, 2, 3 4, 5, 6 => nil irb(main):039:0> b.each_slice(3) do |slice| irb(main):040:1* puts slice.join(", ") irb(main):041:1> end 1, 2, 3 4, 5 This way, you don't have to worry about it, since you are always grabbing the first three. On Dec 17, 2007 5:41 PM, Corey Haines wrote: > Why not get the arrays: > > irb(main):022:0> a > => [1, 2, 3, 4, 5, 6] > irb(main):023:0> a.slice(0,3) > => [1, 2, 3] > irb(main):024:0> a.slice(3,3) > => [4, 5, 6] > irb(main):025:0> b > => [1, 2, 3, 4, 5] > irb(main):026:0> b.slice(0,3) > => [1, 2, 3] > irb(main):027:0> b.slice(3,3) > => [4, 5] > > then loop over them creating the columns. > > -corey > > > > > On Dec 17, 2007 4:12 PM, Jari Williamsson > > wrote: > > Tom Norian wrote: > > > > > How do I divide a number (integer) by 2 and get a result that is like: > > > > > > 5/2 I want 3 > > > 6/2 I want 3 > > > 7/2 I want 4 > > > > Here's another way, one integer division, but 2 instructions: > > > > a = 5.divmod(2) > > result = a[1] + a[2] > > > > > > Best regards, > > > > Jari Williamsson > > > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines