-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.rb
More file actions
50 lines (41 loc) · 663 Bytes
/
text.rb
File metadata and controls
50 lines (41 loc) · 663 Bytes
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
require 'csv'
class Text
def opens()
@fh = open "test.csv"
@mas = []
while (line = @fh.gets)
@mas.insert(@mas.length, line.to_f)
end
@fh.close
return @mas
end
def choice()
puts "Enter what you need to count (x-max, n-min, a-average, d-dispersion)"
@n = gets.chomp
end
def match()
@avr = @mas.reduce(:+) / @mas.length
@dis = 0
case @n
when "x"
@mas.max
when "n"
@mas.min
when "a"
@avr
when "d"
@mas.each do |i|
@dis = @dis + (i - @avr) * 2
end
@dis / (@mas.length - 1)
end
end
def out
puts match
end
end
txt = Text.new
txt.opens
txt.choice
txt.match
txt.out