Created
July 8, 2015 11:36
-
-
Save dasibre/daecd58a1d485e9a3be2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 results = [] | |
| 2 data = File.open("./weather.txt") do |f| | |
| 3 lines = f.readlines.drop(2) | |
| 4 lines.delete_at(-1) | |
| 5 lines.each do |line| | |
| 6 temp_hash = Hash.new {|h,k| h[k]={}} | |
| 7 day,max,min = line.split(' ') | |
| 8 temp_hash[day] = {min:min,max:max} | |
| 9 results << temp_hash | |
| 10 end | |
| 11 results | |
| 12 end | |
| 13 | |
| 14 temp_data = data.each_with_object([]) do |hash,results| | |
| 15 hash.each_pair do |k,v| | |
| 16 results << [k,v[:max].to_i - v[:min].to_i] | |
| 17 end | |
| 18 results | |
| 19 end | |
| 20 temp_set = Hash[temp_data] | |
| 21 p temp_set.min_by {|k,v| v} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
header = f.gets
space = f.gets
def remove_header_space(lines_arry)
the file starts with header and black space and ends with monthly total
not using them at the moment
lines_arry.drop(2)
lines_arry.delete_at(-1)
lines_arry
end