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
|
#!/usr/bin/env ruby
=begin
----------------------------------
AUTHOR: Robert DiCicco
DATE : 2023-03-07
Challenge 207 H-Index ( Ruby)
==================================
=end
citations = [10,8,5,4,3],[25,8,5,3,3]
def CalcIndex(c)
ln = c.length()
offset = ln - 1
pos = ln
while offset >= 0
if c[offset] >= pos
puts("Output: #{pos}")
puts
return
else
offset -= 1
pos -= 1
end
end
end
citations.each do |c|
puts("Input: @citations = #{c}")
CalcIndex(c)
end
=begin
==================================
SAMPLE OUTPUT
ruby .\HIndex.rb
Input: @citations = [10, 8, 5, 4, 3]
Output: 4
Input: @citations = [25, 8, 5, 3, 3]
Output: 3
==================================
=end
|