Class: Six45::Seeds

Inherits:
Object
  • Object
show all
Defined in:
lib/six45/seeds.rb

Instance Method Summary collapse

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_seedObject



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