--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(',')}] #{'<