forked from vikingeducation/prep_ruby_challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounting.rb
More file actions
95 lines (73 loc) · 1.49 KB
/
counting.rb
File metadata and controls
95 lines (73 loc) · 1.49 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def count(total_number, friends)
number = 1
direction = 1
friend = 0
while number <= total_number
puts "#{friends[friend]} says #{number}"
if number % 7 == 0
if direction == 1
direction = -1
else
direction = 1
end
end
if number % 11 == 0
if direction == 1 && friend == 9
friend = 0
elsif direction == -1 && friend == 0
friend = 9
else
friend += direction
end
end
if direction == 1 && friend == 9
friend = 0
elsif direction == -1 && friend == 0
friend = 9
else
friend += direction
end
number += 1
end
end
count(100, ["Jim", "Garrett", "Sammie", "Dave", "Will", "Bubba", "Billy", "Sabrina", "Fake Billy", "Fat Garrett"])
=begin
Advanced version follows
=end
def count(friends, total_number)
number = 1
direction = 1
friend = 1
while number <= total_number
puts "Friend #{friend} says #{number}"
if number % 7 == 0
if direction == 1
direction = -1
else
direction = 1
end
end
if number % 11 == 0
if direction == 1 && friend == friends
friend = 1
elsif direction == -1 && friend == 1
friend = friends
else
friend += direction
end
end
if direction == 1 && friend == friends
friend = 1
elsif direction == -1 && friend == 1
friend = friends
else
friend += direction
end
number += 1
end
end
puts "Enter the number of friends"
counters = gets.chomp.to_i
puts "How high do you want them to count?"
count_total = gets.chomp.to_i
count(counters, count_total)