six45 0.0.2 → 0.0.3
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.
- data/README.md +5 -3
- data/bin/six45 +3 -0
- data/lib/six45/version.rb +1 -1
- data/lib/six45.rb +16 -6
- data/spec/six45_spec.rb +36 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -20,9 +20,11 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Run 'six45' in commandline:
|
22
22
|
|
23
|
-
# six45 => Returns 10 games
|
24
|
-
# six45 30 => Returns 30 games
|
25
|
-
# six45 magic => Returns at least 7 games, which will cover at least 23 numbers
|
23
|
+
# six45 => Returns 10 standard games.
|
24
|
+
# six45 30 => Returns 30 standard games.
|
25
|
+
# six45 magic => Returns at least 7 games, which will cover at least 23 numbers from 45.
|
26
|
+
# six45 system => Returns 1 system game, which contains 8 numbers from 45 (Default: System 8).
|
27
|
+
# six45 system 9 => Returns 1 system game, which contains 9 numbers from 45 (System 9).
|
26
28
|
|
27
29
|
## Contributing
|
28
30
|
|
data/bin/six45
CHANGED
@@ -5,6 +5,9 @@ require 'pp'
|
|
5
5
|
|
6
6
|
if ARGV[0] == "magic"
|
7
7
|
Six45.magic_pick.each { |key, game| pp game }
|
8
|
+
elsif ARGV[0] == "system"
|
9
|
+
number_of_numbers = Six45.is_number?(ARGV[1]) ? ARGV[1].to_i : 8
|
10
|
+
Six45.system_pick(number_of_numbers).each { |key, game| pp game }
|
8
11
|
else
|
9
12
|
number_of_games = Six45.is_number?(ARGV[0]) ? ARGV[0].to_i : 10
|
10
13
|
Six45.pick(number_of_games).each { |key, game| pp game }
|
data/lib/six45/version.rb
CHANGED
data/lib/six45.rb
CHANGED
@@ -8,8 +8,8 @@ module Six45
|
|
8
8
|
Seeds.new.generate seed_size
|
9
9
|
end
|
10
10
|
|
11
|
-
def lucky_candidates
|
12
|
-
lucky_seed =
|
11
|
+
def lucky_candidates(seed_size=6)
|
12
|
+
lucky_seed = Seeds.new.generate seed_size
|
13
13
|
candidates = []
|
14
14
|
while lucky_seed.size > 0
|
15
15
|
candidates << lucky_seed.inject { |sum, d| sum+d }
|
@@ -18,10 +18,10 @@ module Six45
|
|
18
18
|
candidates.sort
|
19
19
|
end
|
20
20
|
|
21
|
-
def lucky_numbers
|
22
|
-
numbers = lucky_candidates
|
21
|
+
def lucky_numbers(game_size=6)
|
22
|
+
numbers = lucky_candidates game_size
|
23
23
|
if numbers.any? { |d| d > 45 } || numbers.inject { |sum, d| sum+d } < 60
|
24
|
-
lucky_numbers
|
24
|
+
lucky_numbers game_size
|
25
25
|
else
|
26
26
|
numbers
|
27
27
|
end
|
@@ -37,7 +37,8 @@ module Six45
|
|
37
37
|
|
38
38
|
def magic_seed
|
39
39
|
a_magic_seed = seed 5
|
40
|
-
|
40
|
+
sum_of_the_seed = a_magic_seed.inject { |sum, n| sum+n }
|
41
|
+
if sum_of_the_seed>36 || is_odd?(sum_of_the_seed)
|
41
42
|
magic_seed
|
42
43
|
else
|
43
44
|
a_magic_seed
|
@@ -61,8 +62,17 @@ module Six45
|
|
61
62
|
magic_games
|
62
63
|
end
|
63
64
|
|
65
|
+
def system_pick(size_of_games=8)
|
66
|
+
{ 1 => (lucky_numbers size_of_games) }
|
67
|
+
end
|
68
|
+
|
64
69
|
def is_number?(i)
|
65
70
|
true if Float(i) rescue false
|
66
71
|
end
|
67
72
|
|
73
|
+
private
|
74
|
+
def is_odd?(number)
|
75
|
+
number%2 == 1 ? true : false
|
76
|
+
end
|
77
|
+
|
68
78
|
end
|
data/spec/six45_spec.rb
CHANGED
@@ -63,18 +63,50 @@ describe Six45 do
|
|
63
63
|
it "returns a hash" do
|
64
64
|
lucky_numbers.should be_kind_of(Hash)
|
65
65
|
end
|
66
|
-
it "containing at least
|
67
|
-
lucky_numbers.size.should be >=
|
66
|
+
it "containing at least 8 games" do
|
67
|
+
lucky_numbers.size.should be >= 8
|
68
68
|
end
|
69
|
-
it "each game contains 6
|
69
|
+
it "each game contains 6 unique numbers" do
|
70
70
|
lucky_numbers.each do |k, g|
|
71
71
|
g.size.should eq g.uniq.size
|
72
72
|
g.size.should eq 6
|
73
73
|
end
|
74
74
|
end
|
75
75
|
it "all games cover at least 23 numbers" do
|
76
|
-
all_numbers = lucky_numbers.map{|k,v| v}.flatten.uniq
|
76
|
+
all_numbers = lucky_numbers.map { |k, v| v }.flatten.uniq
|
77
77
|
all_numbers.size.should be > 23
|
78
78
|
end
|
79
|
+
it "always returns even number of games" do
|
80
|
+
(lucky_numbers.size%2).should be 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "#system_pick" do
|
85
|
+
let(:lucky_numbers) { Six45.system_pick }
|
86
|
+
let(:pick_nine) { lambda { Six45.system_pick 9 } }
|
87
|
+
it "returns a hash" do
|
88
|
+
lucky_numbers.should be_kind_of(Hash)
|
89
|
+
end
|
90
|
+
it "containing 1 game" do
|
91
|
+
lucky_numbers.size.should be 1
|
92
|
+
end
|
93
|
+
it "the game contains 8 unique numbers" do
|
94
|
+
lucky_numbers.each do |k, g|
|
95
|
+
g.size.should eq g.uniq.size
|
96
|
+
g.size.should eq 8
|
97
|
+
end
|
98
|
+
end
|
99
|
+
it "also accepts an integer argument 9" do
|
100
|
+
pick_nine.call.should_not raise_error ArgumentError
|
101
|
+
end
|
102
|
+
it "returns a hash" do
|
103
|
+
pick_nine.call.should be_kind_of(Hash)
|
104
|
+
end
|
105
|
+
it "containing 1 game" do
|
106
|
+
pick_nine.call.size.should be 1
|
107
|
+
end
|
108
|
+
it "the game contains 9 unique numbers" do
|
109
|
+
pick_nine.call[1].size.should be 9
|
110
|
+
end
|
79
111
|
end
|
80
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: six45
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Gem helps pick 6 digits out of 45.
|
15
15
|
email:
|