Created
February 27, 2012 20:15
-
-
Save Canx/1926735 to your computer and use it in GitHub Desktop.
kata 4: data munging (part 2)
This file contains 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
data = Array.new | |
File.foreach("football.dat") { |line| | |
if line =~ /^\s+[0-9]+[.]\s([a-zA-Z_]+)\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+([0-9]+)\s+-\s+([0-9]+)/ then | |
data << { :team => $1, :goal_diff => (Integer($2) - Integer($3)).abs } | |
end | |
} | |
puts data.min { |a,b| a[:goal_diff] <=> b[:goal_diff] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment