Module: GamesDice::ProbabilityValidations::ClassMethods
- Defined in:
- lib/games_dice/prob_helpers.rb
Instance Method Summary collapse
-
#prob_ao_to_h(a, o) ⇒ Object
Convert array,offset notation to hash.
-
#prob_h_to_ao(h) ⇒ Object
Convert hash to array,offset notation.
Instance Method Details
#prob_ao_to_h(a, o) ⇒ Object
Convert array,offset notation to hash
48 49 50 51 52 |
# File 'lib/games_dice/prob_helpers.rb', line 48 def prob_ao_to_h a, o h = Hash.new a.each_with_index { |v,i| h[i+o] = v if v > 0.0 } h end |
#prob_h_to_ao(h) ⇒ Object
Convert hash to array,offset notation
37 38 39 40 41 42 43 44 45 |
# File 'lib/games_dice/prob_helpers.rb', line 37 def prob_h_to_ao h rmin,rmax = h.keys.minmax o = rmin s = 1 + rmax - rmin raise ArgumentError, "Range of possible results too large" if s > 1000000 a = Array.new( s, 0.0 ) h.each { |k,v| a[k-rmin] = Float(v) } [a,o] end |