File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
solutions/standing-ovation/ruby Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments