Skip to content

Instantly share code, notes, and snippets.

@showell
Created April 7, 2011 05:04
Show Gist options
  • Save showell/907068 to your computer and use it in GitHub Desktop.
Save showell/907068 to your computer and use it in GitHub Desktop.
weather part of "data munging" kata
require 'pp'
def lines(fn)
File.open(fn) do |f|
return f.readlines
end
end
def data
lines('weather.dat').map do |line|
if line =~ /(\d+)\s+(\d+)\s+(\d+)/
[$1, $2, $3].map { |col| col.to_i }
end
end.compact
end
strangest_day = data.max_by do |day, max, min|
max - min
end
pp strangest_day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment