fortune 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +19 -0
  2. data/lib/fortune/version.rb +1 -1
  3. metadata +3 -3
data/README.md CHANGED
@@ -31,16 +31,21 @@ Or install it yourself as:
31
31
  #### For Hash
32
32
 
33
33
  Recalculation of the key values to probability, assuming that P = 1
34
+
34
35
  ```ruby
35
36
  {:a => 1, :b => 2, :c => 3}.to_p
36
37
  # => {:a=>0.16666666666666666, :b=>0.3333333333333333, :c=>0.5}
37
38
  ```
39
+
38
40
  Select random key by value weights
41
+
39
42
  ```ruby
40
43
  {:a => 1, :b => 2, :c => 3}.choose
41
44
  # => return :c with 50% probability, :a ~ 16%, :b ~ 33%
42
45
  ```
46
+
43
47
  Choose from set by value weights
48
+
44
49
  ```ruby
45
50
  {[:a, :b, :c] => 1, [:d] => 3}.choose_set
46
51
  # => return :d with 75% probability
@@ -49,6 +54,7 @@ Choose from set by value weights
49
54
  #### Probability
50
55
 
51
56
  Some methods for P
57
+
52
58
  ```ruby
53
59
  p = Fortune::P.new(:m => 1, :n => 10)
54
60
  p = Fortune::P.new(1, 10)
@@ -65,14 +71,19 @@ p.odds.to_s # => "1:9.0 on_win (p: 10.00%)"
65
71
  ```
66
72
 
67
73
  Check event is occured
74
+
68
75
  ```ruby
69
76
  Fortune::P.is(1,10) # => false (90%)
70
77
  ```
78
+
71
79
  Select random element
80
+
72
81
  ```ruby
73
82
  Fortune::P.n(3) # => 1 or 2 or 3
74
83
  ```
84
+
75
85
  Select random key from array or range by weights ({P.n(key) => weight, ...}, P(sum(weights)) = 1)
86
+
76
87
  ```ruby
77
88
  Fortune::P.n_select(10 => 1, 5 => 1000) # => 4
78
89
  Fortune::P.n_select((1..10) => 1, (100..200) => 1000) # => 157
@@ -81,6 +92,7 @@ Fortune::P.n_select([:a,:b,:c] => 1, [:d,:e] => 1000) # => :d
81
92
 
82
93
  #### Odds
83
94
  Class for odds calculations
95
+
84
96
  ```ruby
85
97
  odds = Fortune::Odds.new(:win => 5, :lose => 6)
86
98
  # => #<Fortune::Odds:0x000000026ccf08 @p=0.45454545454545453, @s=5, @k=6, @type=:on_win>
@@ -90,13 +102,17 @@ odds > odds_other # => true
90
102
  odds.variants # => 11
91
103
  odds.p # => 0.45454545454545453
92
104
  ```
105
+
93
106
  Large values can be simple converted to human view
107
+
94
108
  ```ruby
95
109
  Fortune::Odds.new(:win => 1345, :lose => 3623).to_s # => "1345:3623 on_win (p: 27.07%)"
96
110
  Fortune::Odds.new(:win => 1345, :lose => 3623).to_human.to_s # => "2:5 on_win (p: 28.57%)"
97
111
  Fortune::Odds.new(:win => 1345, :lose => 3623).to_human(:k => 5, :fractions => true).to_s # => "1.5:4 on_win (p: 27.27%)"
98
112
  ```
113
+
99
114
  Reverse odds to lose
115
+
100
116
  ```ruby
101
117
  odds = Fortune::Odds.new(:win => 5, :lose => 6)
102
118
  # => #<Fortune::Odds:0x00000002822e98 @p=0.45454545454545453, @s=5, @k=6, @type=:on_win>
@@ -113,6 +129,7 @@ odds.to_lose
113
129
  Permutation without repetition with select k elements.
114
130
 
115
131
  Example: 20 different elements and you need select 5 of them (how many ways of selection exists?). Elements is ordered ([a,b,c] != [b,c,a])
132
+
116
133
  ```ruby
117
134
  Fortune::A.calc(:elements => 10, :select => 5) # => 30240
118
135
  ```
@@ -126,7 +143,9 @@ Example: the amount of distributions of the four teams in four places
126
143
  ```ruby
127
144
  Fortune::Pn.calc(4) # => 24
128
145
  ```
146
+
129
147
  other examples
148
+
130
149
  ```ruby
131
150
  Fortune::Pn.calc(:elements => 5) # => 120
132
151
  Fortune::Pn.calc(:elements => 5, :select => 2) # => 20
@@ -1,3 +1,3 @@
1
1
  module Fortune
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortune
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: 3317073877623941602
117
+ hash: -3789787947405274073
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: 3317073877623941602
126
+ hash: -3789787947405274073
127
127
  requirements: []
128
128
  rubyforge_project:
129
129
  rubygems_version: 1.8.25