From 880a14ad02f01f223ac77d2ae90988ef6f3aeb67 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 9 Dec 2015 22:12:53 -0800 Subject: [PATCH] Day 9.0 --- day_09.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 day_09.rb diff --git a/day_09.rb b/day_09.rb new file mode 100644 index 0000000..7e8179c --- /dev/null +++ b/day_09.rb @@ -0,0 +1,38 @@ +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(&:+) }.min +__END__ +Faerun to Tristram = 65 +Faerun to Tambi = 129 +Faerun to Norrath = 144 +Faerun to Snowdin = 71 +Faerun to Straylight = 137 +Faerun to AlphaCentauri = 3 +Faerun to Arbre = 149 +Tristram to Tambi = 63 +Tristram to Norrath = 4 +Tristram to Snowdin = 105 +Tristram to Straylight = 125 +Tristram to AlphaCentauri = 55 +Tristram to Arbre = 14 +Tambi to Norrath = 68 +Tambi to Snowdin = 52 +Tambi to Straylight = 65 +Tambi to AlphaCentauri = 22 +Tambi to Arbre = 143 +Norrath to Snowdin = 8 +Norrath to Straylight = 23 +Norrath to AlphaCentauri = 136 +Norrath to Arbre = 115 +Snowdin to Straylight = 101 +Snowdin to AlphaCentauri = 84 +Snowdin to Arbre = 96 +Straylight to AlphaCentauri = 107 +Straylight to Arbre = 14 +AlphaCentauri to Arbre = 46