# Re: Probable Iterations (#141)

**URL:** <https://www.ruby-forum.com/t/re-probable-iterations-141/116073>\
**Category:** Ruby\
**Created:** [October 2, 2007, 3:35am UTC](https://www.ruby-forum.com/t/re-probable-iterations-141/116073 "2007-10-02T03:35:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jameskelly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jameskelly](https://www.ruby-forum.com/u/jameskelly)\
**Post date:** [October 2, 2007, 3:35am UTC](https://www.ruby-forum.com/t/re-probable-iterations-141/116073/1 "2007-10-02T03:35:45Z")

</div>

This week’s quiz was extremely simple. My solution mostly-worked on the  
first try.

DES\_NUMBER = 5  
DICE\_SIDES = 6

verbose = ARGV.include? “-v”  
sample = ARGV.include? “-s”

dice = ARGV[-2].to\_i  
min\_des = ARGV[-1].to\_i

pos\_outcomes = DICE\_SIDES \*\* dice  
des\_outcomes = 0

max\_digits = pos\_outcomes.to\_s.size

state = [1]\*dice

1.upto(pos\_outcomes) do |i|  
des\_outcomes += 1 if state.select{|x|1==x}.size \>= min\_des  
puts “%#{max\_digits}d %s” % [i, state.inspect] if  
verbose or sample && i % 50000 == 1  
state[0] += 1  
break if i == pos\_outcomes  
state.each\_with\_index do |n, idx|  
if n \> DICE\_SIDES  
state[idx] = 1  
state[idx+1] += 1  
end  
end  
end

print “\n\n”  
puts “Number of desirable outcomes is #{des\_outcomes}”  
puts “Number of possible outcomes is #{pos\_outcomes}\n”  
puts “Probability is #{des\_outcomes.to\_f/pos\_outcomes}”
