Class: Six45::Seeds
- Inherits:
-
Object
- Object
- Six45::Seeds
- Defined in:
- lib/six45/seeds.rb
Instance Method Summary collapse
- #generate(seed_size = 6) ⇒ Object
-
#initialize(min = 1, max = 13) ⇒ Seeds
constructor
A new instance of Seeds.
- #lucky_numbers(game_size = 6) ⇒ Object
- #magic_seed ⇒ Object
Constructor Details
#initialize(min = 1, max = 13) ⇒ Seeds
Returns a new instance of Seeds.
4 5 6 7 |
# File 'lib/six45/seeds.rb', line 4 def initialize(min=1, max=13) @min = min @max = max end |
Instance Method Details
#generate(seed_size = 6) ⇒ Object
9 10 11 |
# File 'lib/six45/seeds.rb', line 9 def generate(seed_size=6) seed_size.times.map { rand(@min..@max) } end |
#lucky_numbers(game_size = 6) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/six45/seeds.rb', line 23 def lucky_numbers(game_size=6) lucky_seed = generate game_size numbers = [] while lucky_seed.size > 0 numbers << lucky_seed.inject(0, &:+) lucky_seed.pop end if numbers.any? { |d| d > 45 } || numbers.uniq.size < game_size || numbers.inject(0, &:+) < 60 lucky_numbers game_size else numbers.sort end end |
#magic_seed ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/six45/seeds.rb', line 13 def magic_seed a_magic_seed = generate 5 sum_of_the_seed = a_magic_seed.inject(0, &:+) if sum_of_the_seed>36 || sum_of_the_seed.odd? magic_seed else a_magic_seed end end |