1
2
3
4
5
6
7
8
9
10
# require "letters"
distances = Hash.new {|h,k| h[k] = {} }
DATA.read.scan(/^(.*) to (.*) = (.*)$/).each do |from, to, distance|
  distance = distance.to_i
  distances[to][from] = distance
  distances[from][to] = distance
end
locations = distances.keys
puts locations.permutation.map {|p| p.each_cons(2).map {|a,b| distances[a][b] }.inject(&:+) }.max
__END__