Skip to content

Commit 7594efe

Browse files
committed
Approach 5 moved to correct path in standing ovation
1 parent 6e2e2fe commit 7594efe

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def reset_globals()
2+
$audience_string = ""
3+
$chars = []
4+
end
5+
6+
def main(index, chars)
7+
standing_people = 0
8+
invited = 0
9+
10+
chars.each_with_index do |char, index|
11+
number_of_people = char.to_i
12+
13+
if number_of_people > 0
14+
if index <= standing_people
15+
standing_people = standing_people + number_of_people
16+
else
17+
invited = invited + (index - standing_people)
18+
standing_people = standing_people + number_of_people + index - standing_people
19+
end
20+
end
21+
end
22+
23+
print "Persons to be invited: #{invited}\n"
24+
# Write to output file
25+
output = 'Case #' + "#{index}: #{invited}\n"
26+
#IO.write(, output)
27+
open("./large_dataset.out", "a") do |f|
28+
f.puts output
29+
end
30+
end
31+
32+
File.open("./A-large-practice.in", "r") do |f|
33+
f.each_with_index do |line, index|
34+
if index == 0
35+
next
36+
end
37+
38+
line_arr = line.split(" ")
39+
$audience_string = line_arr[1]
40+
$chars = $audience_string.split("")
41+
print "Case #{index} #{$chars}\n"
42+
main(index, $chars)
43+
reset_globals()
44+
end
45+
end

0 commit comments

Comments
 (0)