-
Notifications
You must be signed in to change notification settings - Fork 0
/
FizzBuzz.rb
64 lines (56 loc) · 1.23 KB
/
FizzBuzz.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def fizzbuzz
def maximum_number_request
puts "Input a maximum number"
return gets.chomp.to_i
end
maximum_number = maximum_number_request
for i in 1..maximum_number
def multiple_of_eleven(i)
i % 11 == 0 ? @result << @bong : nil
end
@result = []
@fizz = 'Fizz'
@fezz = 'Fezz'
@buzz = 'Buzz'
@bang = 'Bang'
@bong = 'Bong'
multiple_of_eleven_rule = true
multiple_of_eleven_rule ? multiple_of_eleven(i) : nil
if i % 3 == 0
@result << @fizz
if i % 5 == 0
@result << @buzz
if i % 7 == 0
@result << @bang
end
else
if i % 7 == 0
@result << @bang
end
end
elsif i % 5 == 0
@result << @buzz
if i % 7 == 0
@result << @bang
end
elsif i % 7 == 0
@result << @bang
elsif i % 13 == 0
@result << @fezz
else
@result << i
end
if i % 13 == 0 && @result[0] != @fezz
if @result[0] == @fizz
@result.insert(1,@fezz)
else
@result.insert(0,@fezz)
end
end
if i % 17 == 0
@result = @result.reverse
end
puts @result.join
end
end
fizzbuzz