Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # method definition
- def create_array(data) # change to whatever
- data.chomp.split(' ').map(&:to_i) # returns array of ints
- end
- def calc_average(data) # change to whatever
- data.inject(0, :+).fdiv(2) # returns a float
- end
- def calc_standard_deviation(data) # change to whatever
- Math.sqrt(data.map {|n| n**2}.inject(0, :+).fdiv(data.size)) #return a float
- end
- def calc_median(data) # change to whatever
- data.sort! # sort the array in ascending order
- (data[data.size-1]).fdiv(2) + data[data.size.fdiv(2)].fdiv(2) # return a float
- end
- unless ARGV.size == 2
- STDERR.puts "Error: Incorrect number of arguements\n\nOK. Goodbye."
- else
- # set command line argument1 and argument2 to in_file and out_file respectivley
- in_file = File.new(ARGV[0], 'r')
- store = in_file.each_line do |line|
- array_of_ints = create_array(line)
- average = calc_average(array_of_ints)
- s_deviation = calc_standard_deviation(array_of_ints)
- median = calc_median(array_of_ints)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment