Old high school files. Lessson notes/codes/projects etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hsf/wesweb01/rep2/3.rb

21 lines
443 B

# 3
def distribution_calc(path)
distro_hash = Hash.new(0)
# Ladda in allt i filen till hashen
fh = File.open(path, "r")
items = fh.readlines()
total = items.length()
items.each do |item|
name, type = item.chomp().split(/\ #/)
distro_hash[type.to_sym()] += 1
end
fh.close()
# Printa ut datan
puts("Total: #{total}")
distro_hash.each do |type, amount| puts("#{type.to_s}: #{amount*100.0/total}%") end
return nil
end