--Apple-Mail-1-341471203
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset-ASCII;
	format­´wed

Begin forwarded message:

> From: Cyrus Farajpour <cjfarajp / usc.edu>
> Date: September 29, 2007 1:09:08 PM CDT
> To: submission / rubyquiz.com
> Subject: Please Forward: Ruby Quiz Submission
>
> Hopefully its not too shabby.  Was fun to do.
>
> ~Cyrus Farajpour
>

--Apple-Mail-1-341471203
Content-Transfer-Encoding: 7bit
Content-Type: text/x-ruby-script;
	x-unix-mode44;
	name┐─e.rb
Content-Disposition: attachment;
	filenameą▀ce.rb

#My first ruby quiz! http://www.rubyquiz.com/quiz141.html
#Cyrus Farajpour 

require 'pp'
class Integer #taken from http://readlist.com/lists/ruby-lang.org/ruby-talk/13/66945.html, by James Edward Gray II
  def fact
    (2..self).inject(1) { |f, n| f * n }
  end
end

class Array
  def count_fives
    count  
    self.each {|element| count +  if element 5}
    count
  end
end

def cnr_loop(dice, count) #combinatorial action sauce
  answer  
  (count..(dice-1)).to_a.reverse.each_with_index do |a,index|
    index + 
    answer + ice.fact / (a.fact * index.fact) * 5**index
  end
  answer
end

def array_for_roll(dice,roll) #kinda like counting in reverse order base 6
  roll - 
  array  rray.new(dice) {|i| 0}
  (0..(dice-1)).to_a.reverse.each do |position|
    if position 0
      array[position]  oll
    else
      array[position]  oll/(6**position)# + 1
      roll - oll/(6**position) * 6**position
    end
  end
  array.collect {|e| e + }
end

ARGV.reverse!
fives  RGV[0].to_i
dice  RGV[1].to_i

if ARGV.include?('-v') #dirty, especially since I use the print twice
  (1..(6**dice)).to_a.each do |num|
    array  rray_for_roll(dice,num)
    puts "#{num.to_s.rjust(10)}  [#{array.join(',')}]  #{'< if array.count_fives > ives}"
  end
end

if ARGV.include?('-s')
  count  
  while count < 6**dice
    array  rray_for_roll(dice,count)
    puts "#{count.to_s.rjust(10)}  [#{array.join(',')}]  #{'< if array.count_fives > ives}"
    count + 0000
  end
end

puts "\nNumber of desirable outcomes is #{cnr_loop(dice,fives)}"
puts "Number of possible outcomes is #{6**dice}"

puts "\nProbability is #{cnr_loop(dice,fives).to_f/(6**dice).to_f}"

--Apple-Mail-1-341471203
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset-ASCII;
	formatwed



--Apple-Mail-1-341471203--