pikk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/lib/pikk/main.rb +1 -2
- data/lib/pikk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97b702d042636b17c668e22f5a6bef93009a512
|
4
|
+
data.tar.gz: e4a863a8a21260328dbf50dccba7a8012bf1e0ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b6c4aad7f320cb141d456197252f77c64bd5c91e4801ee4a01b1f8fbe3c6b27c9ab0d08671d9c24fee11ea736aec4ec4f7b577b041a353618330effec9054bf
|
7
|
+
data.tar.gz: cd701a86d763b4ce87f488ea2fa5fb0196eec9e1905a051cf277c4b9f56e9d3e54b191e385f3c43e5a90dc932635aac24106750a5213feb327af687e46026eac
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
> **WARNING!**
|
24
24
|
> **Your hash should have the keys `:name` and `:weight`!**
|
25
25
|
|
26
|
-
There are two methods. One is `single_select` and the other is `pool`. Former, select one hash object from the array by its weight, and return it. Latter, do an iteration of selection, 50 by default, and return the array.
|
26
|
+
There are two methods. One is `single_select` and the other is `pool`. Former, select one hash object from the array by its weight, and return it. Latter, do an iteration of selection, 50 by default, and return the array. See [examples/](https://github.com/aoozdemir/pikk/blob/master/examples/object_example.rb) for more.
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require 'pikk'
|
@@ -44,19 +44,17 @@ Pikk.pool(ary, pp: true)
|
|
44
44
|
# +-----------------+--------+-------+---------------------+--------------------+
|
45
45
|
# | Name | Weight | Count | Probability | (C/(P*I)) |
|
46
46
|
# +-----------------+--------+-------+---------------------+--------------------+
|
47
|
-
# |
|
48
|
-
# |
|
49
|
-
# |
|
50
|
-
# | d |
|
47
|
+
# | c | 7 | 417 | 0.4117647058823529 | 1.0127142857142857 |
|
48
|
+
# | a | 5.5 | 309 | 0.3235294117647059 | 0.955090909090909 |
|
49
|
+
# | b | 3 | 163 | 0.17647058823529413 | 0.9236666666666666 |
|
50
|
+
# | d | 1.5 | 111 | 0.08823529411764706 | 1.258 |
|
51
51
|
# +-----------------+--------+-------+---------------------+--------------------+
|
52
|
-
# | Iteration Count |
|
52
|
+
# | Iteration Count | 1000 |
|
53
53
|
# +-----------------+--------+-------+---------------------+--------------------+
|
54
|
-
# | Sum Ratio | 0.
|
54
|
+
# | Sum Ratio | 0.03736796536796527 |
|
55
55
|
# +-----------------+--------+-------+---------------------+--------------------+
|
56
56
|
```
|
57
57
|
|
58
|
-
|
59
|
-
|
60
58
|
## Development
|
61
59
|
|
62
60
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/pikk/main.rb
CHANGED
@@ -51,7 +51,7 @@ module Pikk
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def to_table(list = [{}])
|
54
|
-
list.sort_by { |h| h[:weight] }.reverse!
|
54
|
+
list.sort_by! { |h| h[:weight] }.reverse!
|
55
55
|
|
56
56
|
lsum = 0
|
57
57
|
|
@@ -67,7 +67,6 @@ module Pikk
|
|
67
67
|
add_row ['Iteration Count', { value: $iteration, colspan: 4, alignment: :right }]
|
68
68
|
add_separator
|
69
69
|
add_row ['Sum Ratio', { value: (1 - lsum / list.count).abs, colspan: 4, alignment: :right }]
|
70
|
-
align_column 1, :center
|
71
70
|
end
|
72
71
|
|
73
72
|
puts ltable
|
data/lib/pikk/version.rb
CHANGED