Skip to content

Instantly share code, notes, and snippets.

@dasibre
Created July 8, 2015 11:36
Show Gist options
  • Select an option

  • Save dasibre/daecd58a1d485e9a3be2 to your computer and use it in GitHub Desktop.

Select an option

Save dasibre/daecd58a1d485e9a3be2 to your computer and use it in GitHub Desktop.
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}
@dasibre

dasibre commented Jul 8, 2015

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment