# Ruby 1.9.1 Array#combination kinda lazy

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654>\
**Category:** Ruby\
**Created:** [July 15, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654 "2010-07-15T20:30:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 15, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/1 "2010-07-15T20:30:30Z")

</div>

C:\>type tmp.rb  
count = 0  
combo = nil  
(1…166).to\_a.combination(5).each do |c|  
count+= 1; combo = c  
end  
p count, combo

C:\>ruby -v tmp.rb  
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]  
129462338  
[5, 34, 54, 73, 81]

Yeah…no one could possibly need to run more than 129 million  
combinations, and…I’m getting kinda tired, so…yeah, let’s just  
stop here.

WTF?

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 16, 2010, 10:27am UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/2 "2010-07-16T10:27:03Z")

</div>

On Jul 15, 2010, at 11:30 , Phrogz wrote:

> 129462338  
> [5, 34, 54, 73, 81]
> 
> Yeah…no one could possibly need to run more than 129 million  
> combinations, and…I’m getting kinda tired, so…yeah, let’s just  
> stop here.
> 
> WTF?

wfm:

#!/usr/bin/ruby -w

class Integer  
def f!  
(1…self).inject { |prod, n| prod \* n }  
end  
end

expected = ((166.f!)/(5.f! \* 161.f!).to\_f).to\_i # =\> 988455798

count = 0  
combo = nil

(1…166).to\_a.combination(5).each do |c|  
count += 1; combo = c  
end

p count, combo  
p count == expected

# outputs:

# 

# ~/.multiruby/install/1.9.1-p129/bin/ruby wtf.rb

# 988455798

# [162, 163, 164, 165, 166]

# true

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 16, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/3 "2010-07-16T18:47:43Z")

</div>

On Jul 16, 2:20 am, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jul 15, 2010, at 11:30 , Phrogz wrote:
> 
> > C:\>ruby -v tmp.rb  
> > ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]  
> > 129462338  
> > [5, 34, 54, 73, 81]

> wfm:
> 
> # ~/.multiruby/install/1.9.1-p129/bin/ruby wtf.rb
> 
> # 988455798
> 
> # [162, 163, 164, 165, 166]

Just reproduced using 1.9.1p378 on Ubuntu. Looks to me like it’s not a  
Windows bug, but something introduced sometime between p129 and p243.

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 16, 2010, 7:51pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/4 "2010-07-16T19:51:31Z")

</div>

On Jul 16, 2010, at 9:45 AM, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just reproduced using 1.9.1p378 on Ubuntu. Looks to me like it’s not a  
> Windows bug, but something introduced sometime between p129 and p243.

Report on ruby-core@ please.

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 16, 2010, 10:55pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/5 "2010-07-16T22:55:54Z")

</div>

On Jul 15, 12:29 pm, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 129462338  
> [5, 34, 54, 73, 81]

For posterity, this has now been logged as a bug here:  
[http://redmine.ruby-lang.org/issues/show/3581](http://redmine.ruby-lang.org/issues/show/3581)

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [July 16, 2010, 8:50pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-array-combination-kinda-lazy/191654/6 "2010-07-16T20:50:38Z")

</div>

On Jul 16, 10:40 am, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # [162, 163, 164, 165, 166]
> 
> Just reproduced using 1.9.1p378 on Ubuntu. Looks to me like it’s not a  
> Windows bug, but something introduced sometime between p129 and p243.

Interestingly, replacing 166 with 141 produces a RangeError:  
in `combination’: too big for combination

So this bug may be the same or related to  
[http://redmine.ruby-lang.org/issues/show/3089](http://redmine.ruby-lang.org/issues/show/3089),  
which is marked as fixed in 1.9.2.

Will follow up with ruby-core.
