Skip to content

Instantly share code, notes, and snippets.

@Canx
Created February 27, 2012 20:15
Show Gist options
  • Save Canx/1926735 to your computer and use it in GitHub Desktop.
Save Canx/1926735 to your computer and use it in GitHub Desktop.
kata 4: data munging (part 2)
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