public
Created

kata 4: data munging (part 1)

  • Download Gist
kata4_1.rb
Ruby
1 2 3 4 5 6 7 8
data = Array.new
File.foreach("weather.dat") { |line|
if line =~ /^\s+([0-9]+)\s+([0-9]+)[*]?\s+([0-9]+)[*]?/ then
data << {:day => Integer($1), :spread => Integer($2) - Integer($3)}
end
}
 
puts data.min { |a,b| a[:spread] <=> b[:spread] }

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.