You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
# 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__
|
|
Faerun to Norrath = 129
|
|
Faerun to Tristram = 58
|
|
Faerun to AlphaCentauri = 13
|
|
Faerun to Arbre = 24
|
|
Faerun to Snowdin = 60
|
|
Faerun to Tambi = 71
|
|
Faerun to Straylight = 67
|
|
Norrath to Tristram = 142
|
|
Norrath to AlphaCentauri = 15
|
|
Norrath to Arbre = 135
|
|
Norrath to Snowdin = 75
|
|
Norrath to Tambi = 82
|
|
Norrath to Straylight = 54
|
|
Tristram to AlphaCentauri = 118
|
|
Tristram to Arbre = 122
|
|
Tristram to Snowdin = 103
|
|
Tristram to Tambi = 49
|
|
Tristram to Straylight = 97
|
|
AlphaCentauri to Arbre = 116
|
|
AlphaCentauri to Snowdin = 12
|
|
AlphaCentauri to Tambi = 18
|
|
AlphaCentauri to Straylight = 91
|
|
Arbre to Snowdin = 129
|
|
Arbre to Tambi = 53
|
|
Arbre to Straylight = 40
|
|
Snowdin to Tambi = 15
|
|
Snowdin to Straylight = 99
|
|
Tambi to Straylight = 70
|