forked from DesafioLatam/E9CP2A1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.rb
34 lines (30 loc) · 714 Bytes
/
3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Roulette
def initialize
@r = (1..10).to_a
end
def play(bet)
random = @r.sample
puts random
store(random, bet)
puts random == bet ? 'Ganaste' : 'Perdiste'
random == bet
end
def store(random, bet)
write_in_file('roulette_history.txt', random)
write_in_file('winners.txt', bet) if bet == random
end
def write_in_file(file, content)
file = File.open(file, 'a')
file.puts content
file.close
end
def most_repeated
data = []
(0..10).to_a.each { |i| data[i] = 0 }
data_file = File.open('roulette_history.txt', 'r'){ |file| file.readlines }
data_file.each do |line|
data[line.to_i] += 1
end
data.index data.max
end
end